[comp.sources.atari.st] v03i011: kbext410 -- Keyboard remapper

koreth@panarthea.ebay.sun.com (Steven Grimm) (11/15/89)

Submitted-by: BD05@DKAUNI2.Bitnet (Roland Waldi)
Posting-number: Volume 3, Issue 11
Archive-name: kbext410

This is the latest version (4.10) of KBEXT (keyboard extension).
Put KBEXT4.PRG into the AUTO folder, or start it at any time from the
desktop (but only once a session). It will establish a memory resident
extension to the keyboard interrupt handler, which allows in addition to
the NORMAL, SHIFT and CAPS-LOCK keyboard tables also ALT and ALT-SHIFT
keyboard tables to be used, thus allowing more than 128 additional
characters to be entered directly from the keyboard pressing the ALT
key. ALL KEYBOARD TABLES (INCL. THE NON-ALT) OVERRIDE ANY OTHER USER- OR
PROGRAM-DEFINED TABLE, I.E. XBIOS CALL 16 (KEYTBL) HAS NO EFFECT! COLD
BOOT is triggered by pressing CTRL-ALT-rightSHIFT-DEL, WARM BOOT by
pressing CTRL-ALT-DEL (it's interesting to hear TOS 1.4 has this already
built-in :-)).
KBEXT4 contains also a screen saver, which disables the screen 10
minutes after the last mouse/keyboard/midi event; KBEXT3 is without
screen saver.
The program may be freely used, copied and modified, totally at your own
risk and responsibility, and only for non-profit use.

Enjoy,                Roland Waldi, BD05 @ DKAUNI2.BITNET

#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  KBEXT.TXT
#	  KBEXT3.ASM
#	  KBEXT4.ASM
#
sed 's/^X//' << 'SHAR_EOF' > KBEXT.TXT &&
XKBEXT.PRG (Version 2.02-87/09, 3.10-89/11, 4.10-89/11)
X------------------------------------------------------ 
X
XPut KBEXT.PRG into the AUTO folder, or start it at any time from the
Xdesktop (but only once a session). It will establish a memory 
Xresident extension to the keyboard interrupt handler, which allows
Xin addition to the NORMAL, SHIFT and CAPS-LOCK keyboard tables also
XALT and ALT-SHIFT keyboard tables to be used, thus allowing more than
X128 additional characters to be entered directly from the keyboard
Xpressing the ALT key. For use with some programs using ALT+key 
Xcombinations as control keys, use ALT+CTRL+key instead.
X  
XKBEXT version 3.xx does the same, but all keyboard tables (incl. the
Xnon-ALT) override any other user- or program-defined table, i.e. XBIOS
Xcall 16 (keytbl) has no effect! The version 2.xx only initializes the
XTOS keyboard table to its own copies, using keytbl itself, which may be
Xreplaced or abandoned later by any other program.
X
XKBEXT version 4.xx is KBEXT 3.xx plus a screen saver, which disables 
Xthe screen 10 minutes after the last mouse/keyboard/midi event. 
XKBEXT version 4.02 adds a cold boot by pressing CTRL-ALT-rightSHIFT-DEL.
XKBEXT version 4.10 adds a warm boot by pressing CTRL-ALT-DEL.
X
XIf you use KBEXT.PRG as it is, you will get the following keyboard
Xlayout (which is close to the US and GB version of the ATARI keyboard
Xfor the non-ALT keys):
X
XNORMAL:
X
XF1 /F2 /F3 /F4 /F5 /F6 /F7 /F8 /F9 /F10/ 
X 
XEsc 1 2 3 4 5 6 7 8 9 0 - = `   Bsp  Help     Undo   (   )  /    *
XTab  q w e r t y u i o p [ ]    Del  Insrt Up  Clr   7   8  9    -
XCtrl  a s d f g h j k l ; '  Ret  #  Left Dwn Rght   4   5  6    +
XShft \ z x c v b n m , . /  Shft                     1   2  3  Ent
X    Alt  -----Space-----  CpsL                         0    .
X
XSHIFT (note that no digits appear with the cursor keys, which
Xmeans you need not release the SHIFT key to move the cursor!)
X 
XF11/F12/F13/F14/F15/F16/F17/F18/F19/F20/
X                             
XEsc ! @ # $ % ^ & * ( ) _ + :   Bsp  Help     Undo   (   )  /    *
XTab  Q W E R T Y U I O P { }    Del  Insrt Up  Clr   7   8  9    -
XCtrl  A S D F G H J K L : "  Ret  ~  Left Dwn Rght   4   5  6    +
XShft | Z X C V B N M < > ?  Shft                     1   2  3  Ent
X    Alt  -----Space-----  CpsL                         0    .
X
XCAPS-LOCK: 
X 
XF1 /F2 /F3 /F4 /F5 /F6 /F7 /F8 /F9 /F10/ 
X 
XEsc 1 2 3 4 5 6 7 8 9 0 - = `   Bsp  Help     Undo   (   )  /    *
XTab  Q W E R T Y U I O P [ ]    Del  Insrt Up  Clr   7   8  9    -
XCtrl  A S D F G H J K L ; '  Ret  #  Left Dwn Rght   4   5  6    +
XShft \ Z X C V B N M , . /  Shft                     1   2  3  Ent
X    Alt  -----Space-----  CpsL                         0    .
X
XALT: 
X 
XF1 /F2 /F3 /F4 /F5 /F6 /F7 /F8 /F9 /F10/ 
X 
XEsc ; +  , ? ) = y x 2  p K   Bsp  SDump           `   a  m    o
XTab   B 	 U g     c G u    Del  LMous MUp RMs   !     
XCtrl    k  D F @ L M H J  Ret    MLeft MDn MRgt            X
XShft 4 0 1  ^ C $ f [ \ 3  Shft                          
  Ent
X    Alt  -----Space-----  CpsL                         i    e
X
XSHIFT & ALT:
X 
XF11/F12/F13/F14/F15/F16/F17/F18/F19/F20/ 
X 
XEsc - 9 ]  v * > z & ' w q    Bsp  SDump           .   /  h    6
XTab   V n T S   l  < O t    Del  LMous Mup RMs   "         Z
XCtrl   d E N b I A Q R S T  Ret    Mleft Mdn Mrgt  #         W
XShft 5 7 8  { _ % P s r (  Shft                        }  ~  Ent
X    Alt  -----Space-----  CpsL                         j    |
X
XThere are at least two ways to change the keyboard assignment:
X 
X1. Change the keyboard tables in KBEXT.ASM and reassemble the
X   program. You may have to change some control statements
X   to fit your assembler's requirements, but the program is
X   written to make changes even to MEGAMAX-C-Inline-Assembler 
X   not too hard (Use a minimal INIT.C here to save memory and
X   to provide basepage information). 
X 
X2. Use any PD keyboard-changing program, which allows to
X   save a xxx.KBD file (check if it has 384 bytes), e.g.
X   MOBZKEY.ACC, and make two files: DEFAULT.KBD for the 
X   normal keyboard assignment, and ALT.KBD with the
X   unshifted and shifted ALT keyboard assignments (don't
X   change the caps-lock table here, you will need CAPS LOCK
X   to type into the file-selector box, since MOBZKEY changes
X   the keyboard assignment immediately!). 
X 
X   Put these two files into the \AUTO\ folder of your boot disk,
X   if you use KBEXT at boot time, or into the \AUTO\ folder of
X   your working disk containig KBEXT(4).PRG otherwise.
X   From now on the tables in these datasets will be used, when KBEXT
X   is run.
X
X3. A third possibility would be to make the files DEFAULT.KBD and
X   ALT.KBD mentioned in (2) by a separate program, e.g. a file monitor
X   etc. The format of a KBD file is simply 3 times 128 bytes of the
X   keyboard tables (one byte per character) for normal, shifted and
X   caps-lock. The key numbers (hexadecimal) are:
X
X3B /3C /3D /3E /3F /40 /41 /42 /43 /44 / 
X 
X01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 29  0E  62    61  63 64 65 66
X0F  10 11 12 13 14 15 16 17 18 19 1A 1B    53  52 48 47  67 68 69 4A
X[1D] 1E 1F 20 21 22 23 24 25 26 27 28   1C 2B  4B 50 4D  6A 6B 6C 4E
X[2A](60)2C 2D 2E 2F 30 31 32 33 34 35 [36]               6D 6E 6F 72
X   [38]  -------39------  [3A]                            70   71
X 
X   Note that US keyboards don't have the key (60). You should assign
X   0 to all function keys, and to the positions that do not belong
X   to any key. Key number redefinitions used by TOS with the ALT key are
X   automatically taken into account by KBEXT, after reading the ALT.KBD
X   file; so the numbers given above should be used for all 5 tables.
X 
X4. Finally, you can also patch the program code: you find all tables 
X   contiguous after "KBEXT/RW" in the order normal - shift - caps - 
X   alt - shift/alt. You can use your favourite disk-/file monitor  
X   to change these tables in KBEXT(4).PRG.
X 
XThe program may be freely used, copied and modified, totally at your
Xown risk and responsibility, and only for non-profit use.
X
XEnjoy,                Roland Waldi, BD05 @ DKAUNI2.BITNET
SHAR_EOF
chmod 0600 KBEXT.TXT || echo "restore of KBEXT.TXT fails"
sed 's/^X//' << 'SHAR_EOF' > KBEXT3.ASM &&
X;***************************************************************
X;*                                                             *
X;* KBEXT3.ASM: extend keyboard functions                       *
X;* installs itself in the keyboard interrupt                   *
X;* valid for TOS 1.00 20/11/1985 or TOS 1.2 and following      *
X;*                                                             *
X;* TOS version dependent (marked with **):                     *
X;*     addr. for kbshifts: A5D (TOS 20.06.85 D)                *
X;*                         E1B (TOS 20.11.85 GB)               *
X;*                         E1B (TOS 06.02.86 D)                *
X;*     for TOS 1.2 ff. automatically set                       *
X;*                                                             *
X;* THIS VERSION (3.xx) IGNORES ALL TOS KEYBOARD TABLES         *
X;* HAS A WARMBOOT on Ctrl-Alt-Del                              *
X;* HAS A COLDBOOT on Ctrl-Alt-rightShift-Del                   *
X;* Version for GST-Assembler                                   *
X;*                                                             *
X;***** (C) Roland Waldi *** 3.10-89/11 *************************
X
X          SECTION   MAIN
X          RORG      0
X          BRA       install
X
Xkbint:
X          MOVE.L    (A7)+,RTNadd   ;* return address
X          MOVE.L    TOSvec,A0
X          JSR       (A0)           ;* jump to TOS routine
X          MOVE.L    RTNadd,-(A7)   ;* return address
X          BRA.S     go
X
Xtimerint:
X          MOVE.L    (A7)+,RTNadd   ;* return address
X          MOVE.L    TMRvec,A0
X          JSR       (A0)           ;* call etv_timer
X          MOVE.L    RTNadd,-(A7)   ;* return address
Xgo:
X          MOVE.L    IOrec,A0
X          MOVE.L    (A0),A2        ;* get address of io-buffer
X          MOVE.W    8(A0),D1       ;* tail index
X          CMP.W     OLDtail,D1     ;* test if changed
X          BEQ.S     rturn
X          LEA       OLDtail,A1
X          MOVE.W    D1,(A1)        ;* save tail index at OLDtail
Xkbshadr:  MOVE.B    $E1B,D2        ;* get kbshifts (** TOS dependent **)
X          BTST      #2,D2          ;* CTRL set?
X          BEQ.S     noctrl         ;*   if not, translate
X          BTST      #3,D2          ;* ALT set?
X          BEQ.S     rturn          ;*   if not, return
X          MOVE.W    0(A2,D1.W),D0  ;* get...
X          AND.W     #$7F,D0        ;* ...key code
X          CMP.B     #$53,D0
X          BNE.S     nospecl
X          BTST      #0,D2          ;* right SHIFT set?
X          BNE.S     reset          ; C-A Del: Boot
X          CLR.L     $420           ; C-A-rS Del: Coldboot
X          CLR.L     $426
X          CLR.L     $43A
Xreset:    RESET
Xnospecl:
X          CLR.W     D0
X          BRA.S     store          ;* store 0
Xnoctrl:
X          MOVE.W    0(A2,D1.W),D0  ;* get...
X          AND.W     #$7F,D0        ;* ...key code
X          BTST      #3,D2          ;* ALT set?
X          BNE.S     altkeys        ;*   if 1
X          LEA       normal,A1      ;* get normal table
X          AND.B     #$13,D2        ;* test SHIFT l/r and CapsL
X          BEQ.S     goon           ;*   if none set
X          ADD.W     #128,D0        ;* use second table (SHIFT)
X          AND.B     #$03,D2        ;* only CapsLock set?
X          BNE.S     goon           ;* if not
X          ADD.W     #128,D0        ;* CapsLock table
X          BRA.S     goon
Xaltkeys:
X          LEA       ALTtabl,A1     ;* get translation table
X          AND.B     #$13,D2        ;* test SHIFT l/r and CapsL
X          BEQ.S     goon           ;* if none set
X          ADD.W     #128,D0        ;* use second table (SHIFT)
Xgoon:
X          MOVE.B    0(A1,D0.W),D0  ;* translate
Xstore:
X          MOVE.W    D0,2(A2,D1.W)  ;* store char code
Xrturn:
X          RTS
XTOSvec:
X          DC.L      0
XTMRvec:
X          DC.L      0
XRTNadd:
X          DC.L      0
XIOrec:
X          DC.L      0
XOLDtail:
X          DC.W      -1
Xtag:
X          DC.B      'K','B','E','X','T','/','R','W'
X;*
X;* here are the keyboard tables for normal, SHIFT,
X;*                                  and normal with CAPS LOCK
X;*                                  ALT, ALT&SHIFT
X;* you find them in the compiled program after the tag "KBEXT/RW"
X;*
X;* to change the keyboard layout, use the "normal" table as a
X;* guide for the keys (the layout is for a UK keyboard)
X;* and insert the ATARI/ASCII codes of the characters you want.
X;* NOTE:
X;* with ALT, the positions 02 ('1') ... 09 ('8') move to
X;* 78 ... 7F,
X;* and 0A ('9') ... 0D ('=') to 00 ... 03 (should be 80 ... 83)
X;* these rearrangements are done BY THE PROGRAM, so: fill the
X;* tables according to the normal keycode position.
X;*
Xnormal:
X          DC.B      $00,$1B,'1','2','3','4','5','6' ;* 00 Esc
X          DC.B      '7','8','9','0','-','=',$08,$09 ;* 08 BS,TAB
X          DC.B      'q','w','e','r','t','y','u','i' ;* 10
X          DC.B      'o','p',$5B,$5D,$0D,$00,'a','s' ;* 18 brackets,CR
X          DC.B      'd','f','g','h','j','k','l',';' ;* 20
X          DC.B      $27,'`',$00,'#','z','x','c','v' ;* 28 '
X          DC.B      'b','n','m',',','.','/',$00,$00 ;* 30
X          DC.B      $00,' ',$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,'-',$00,$00,$00,'+',$00 ;* 48
X          DC.B      $00,$00,$00,$7F,$00,$00,$00,$00 ;* 50 DEL
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $5C,$00,$00,'(',')','/','*','7' ;* 60 \
X          DC.B      '8','9','4','5','6','1','2','3' ;* 68
X          DC.B      '0','.',$0D,$00,$00,$00,$00,$00 ;* 70 Enter
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
Xshiftblk:
X          DC.B      $00,$1B,'!','@','#','$','%','^' ;* 00
X          DC.B      '&','*','(',')','_','+',$08,$09 ;* 08
X          DC.B      'Q','W','E','R','T','Y','U','I' ;* 10
X          DC.B      'O','P','{','}',$0D,$00,'A','S' ;* 18
X          DC.B      'D','F','G','H','J','K','L',':' ;* 20
X          DC.B      '"',$BA,$00,'~','Z','X','C','V' ;* 28
X          DC.B      'B','N','M','<','>','?',$00,$00 ;* 30
X          DC.B      $00,' ',$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,'-',$00,$00,$00,'+',$00 ;* 48
X          DC.B      $00,$00,$00,$7F,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      '|',$00,$00,'(',')','/','*','7' ;* 60
X          DC.B      '8','9','4','5','6','1','2','3' ;* 68
X          DC.B      '0','.',$0D,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
Xcapslock:
X          DC.B      $00,$1B,'1','2','3','4','5','6' ;* 00
X          DC.B      '7','8','9','0','-','=',$08,$09 ;* 08
X          DC.B      'Q','W','E','R','T','Y','U','I' ;* 10
X          DC.B      'O','P',$5B,$5D,$0D,$00,'A','S' ;* 18
X          DC.B      'D','F','G','H','J','K','L',';' ;* 20
X          DC.B      $27,'`',$00,'#','Z','X','C','V' ;* 28
X          DC.B      'B','N','M',',','.','/',$00,$00 ;* 30
X          DC.B      $00,' ',$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,'-',$00,$00,$00,'+',$00 ;* 48
X          DC.B      $00,$00,$00,$7F,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $5C,$00,$00,'(',')','/','*','7' ;* 60
X          DC.B      '8','9','4','5','6','1','2','3' ;* 68
X          DC.B      '0','.',$0D,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
XALTtabl:
X          DC.B      $00,$1B,$BB,$AB,$9C,$AC,$BF,$A9 ;* 00 (reduced set)
X          DC.B      $BD,$F9,$F8,$B2,$7F,$F0,$00,$00 ;* 08
X          DC.B      $91,$C2,$89,$D5,$E7,$98,$81,$8B ;* 10
X          DC.B      $94,$E3,$00,$F5,$00,$00,$84,$9E ;* 18
X          DC.B      $EB,$9F,$00,$00,$C0,$00,$00,$00 ;* 20
X          DC.B      $00,$00,$00,$86,$B0,$B1,$87,$DE ;* 28
X          DC.B      $00,$A4,$E6,$DB,$DC,$B3,$00,$00 ;* 30
X          DC.B      $00,$20,$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,$D9,$00,$00,$00,$D8,$00 ;* 48
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $B4,$00,$00,$E0,$E1,$ED,$EF,$A1 ;* 60
X          DC.B      $8C,$8D,$A0,$83,$85,$82,$88,$8A ;* 68
X          DC.B      $E9,$E5,$00,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $BB,$AB,$9C,$AC,$BF,$A9,$BD,$F9 ;* 78
X;* ALT & SHIFT
X          DC.B      $00,$1B,$AD,$B9,$DD,$9B,$F6,$AA ;* 00
X          DC.B      $BE,$FA,$A6,$A7,$F7,$F1,$00,$00 ;* 08
X          DC.B      $92,$D6,$EE,$D4,$D3,$9D,$9A,$EC ;* 10
X          DC.B      $99,$BC,$CF,$F4,$00,$00,$8E,$E4 ;* 18
X          DC.B      $C5,$CE,$E2,$C9,$C1,$D1,$D2,$D3 ;* 20
X          DC.B      $D4,$FF,$00,$8F,$B7,$B8,$80,$FB ;* 28
X          DC.B      $DF,$A5,$D0,$F3,$F2,$A8,$00,$00 ;* 30
X          DC.B      $00,$20,$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,$DA,$00,$00,$00,$D7,$00 ;* 48
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $B5,$00,$00,$AE,$AF,$E8,$B6,$A2 ;* 60
X          DC.B      $93,$95,$A3,$96,$97,$90,$FD,$FE ;* 68
X          DC.B      $EA,$FC,$00,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
X
Xpglength:
X          DC.L      0
Xinstall:
X          MOVEA.L   4(A7),A5       ;* basepage
X          LEA       pglength(PC),A0
X          LEA       install(PC),A1
X          MOVE.L    A1,D0
X          SUB.L     A5,D0          ;* calculate length
X          MOVE.L    D0,(A0)
X          MOVE.L    D0,-(A7)       ;* length
X          MOVE.L    A5,-(A7)       ;* start
X          CLR.W     -(A7)
X          MOVE.W    #$4A,-(A7)
X          TRAP      #1             ;* SETBLOCK, reserve storage
X          LEA       12(A7),A7
X          LEA       messg1(PC),A0  ;* display message
X          BSR       outp
X          CLR.W     -(A7)          ;* read file DEFAULT.KBD
X          PEA       file1(PC)
X          MOVE.W    #$3D,-(A7)     ;* open
X          TRAP      #1
X          ADDQ.L    #8,A7
X          TST.W     D0
X          BMI.S     nodefault
X          PEA       normal(PC)     ;* table address for read
X          MOVE.L    #384,-(A7)     ;* length
X          MOVE.W    D0,-(A7)       ;* handle
X          MOVE.W    #$3F,-(A7)     ;* read
X          TRAP      #1
X          LEA       12(A7),A7
X          MOVE.W    handle(PC),-(A7)
X          MOVE.W    #$3E,-(A7)     ;* close
X          TRAP      #1
X          ADDQ.L    #4,A7
X          LEA       file1(PC),A0   ;* display file1
X          BSR       outp
Xnodefault:
X          LEA       messg2(PC),A0  ;* display message
X          BSR       outp
X          CLR.W     -(A7)          ;* read file ALT.KBD
X          PEA       file2(PC)
X          MOVE.W    #$3D,-(A7)     ;* open
X          TRAP      #1
X          ADDQ.L    #8,A7
X          TST.W     D0
X          BMI.S     noaltfile
X          LEA       handle(PC),A0  ;* file handle
X          MOVE.W    D0,(A0)
X          PEA       ALTtabl(PC)    ;* table address for read
X          MOVE.L    #256,-(A7)     ;* length
X          MOVE.W    D0,-(A7)       ;* handle
X          MOVE.W    #$3F,-(A7)     ;* read
X          TRAP      #1
X          LEA       12(A7),A7
X          MOVE.W    handle(PC),-(A7)
X          MOVE.W    #$3E,-(A7)     ;* close
X          TRAP      #1
X          ADDQ.L    #4,A7
X          LEA       file2(PC),A0   ;* display file2
X          BSR       outp
Xnoaltfile:
X          LEA       ALTtabl(PC),A0 ;* rearrange ALT-Codes
X          MOVE.L    $02(A0),$78(A0)
X          MOVE.L    $06(A0),$7C(A0)
X          MOVE.L    $0A(A0),$00(A0)
X          MOVE.L    $082(A0),$0F8(A0) ;* same for ALT SHIFT
X          MOVE.L    $086(A0),$0FC(A0)
X          MOVE.L    $08A(A0),$080(A0)
X          MOVE.W    #1,-(A7)
X          MOVE.W    #14,-(A7)
X          TRAP      #14            ;* get iorec(1)
X          ADDQ.L    #4,A7
X          LEA       IOrec(PC),A0
X          MOVE.L    D0,(A0)        ;* save pointer to kbd-iorec
X          MOVE.W    #34,-(A7)
X          TRAP      #14            ;* Kbdvbase()
X          ADDQ.L    #2,A7
X          MOVE.L    D0,A1          ;* A1 = addr(kbdvbase)
X          LEA       TOSvec,A0
X          MOVE.L    32(A1),(A0)    ;* save interrupt routine address
X          LEA       kbint,A0
X          MOVE.L    A0,32(A1)      ;* install new interrupt vectors
X          CLR.L     -(A7)
X          MOVE.W    #$20,-(A7)
X          TRAP      #1             ;* Super
X          ADDQ.L    #6,A7
X          LEA       TMRvec,A0
X          MOVE.L    $400,(A0)      ;* save etv_timer routine address
X          LEA       timerint,A0
X          MOVE.L    A0,$400        ;* install new interrupt vector
X          MOVE.L    $4F2,A0        ;* get system address
X          CMPI.B    #2,3(A0)       ;* check subversion number
X          BLT.S     oldsys         ;* TOS < 1.2: keep address
X          MOVE.W    26(A0),kbshadr+2  ;* copy kbshift variable address
Xoldsys:
X          MOVE.L    D0,-(A7)
X          MOVE.W    #$20,-(A7)
X          TRAP      #1
X          ADDQ.L    #6,A7
X          LEA       messg3(PC),A0  ;* newline
X          BSR.S     outp
X          CLR.W     -(A7)          ;* return code
X          MOVE.L    pglength(PC),-(A7) ;* program length
X          MOVE.W    #$31,-(A7)     ;* Ptermres
X          TRAP      #1             ;* reserve storage and end
Xoutp:     MOVE.L    A0,-(A7)
X          MOVE.W    #$09,-(A7)
X          TRAP      #1             ;* print line
X          ADDQ.L    #6,A7
X          RTS                      ;* never reached
Xhandle:   DC.W      0
Xmessg1:   DC.B      $0D,$0A,'KBEXT v. 3.10 installing keyboard ',$00
Xmessg2:   DC.B      $0D,$0A,'------------- and ALT table       ',$00
Xmessg3:   DC.B      $0D,$0A,$00
Xfile1:    DC.B      $5C,'AUTO',$5C
X          DC.B      'DEFAULT.KBD',$00
Xfile2:    DC.B      $5C,'AUTO',$5C
X          DC.B      'ALT.KBD',$00
X          END
SHAR_EOF
chmod 0600 KBEXT3.ASM || echo "restore of KBEXT3.ASM fails"
sed 's/^X//' << 'SHAR_EOF' > KBEXT4.ASM &&
X;***************************************************************
X;*                                                             *
X;* KBEXT4.ASM: extend keyboard functions                       *
X;* installs itself in the keyboard interrupt                   *
X;* valid for TOS 1.00 20/11/1985 or TOS 1.2 and following      *
X;*                                                             *
X;* TOS version dependent (marked with **):                     *
X;*     addr. for kbshifts: A5D (TOS 20.06.85 D)                *
X;*                         E1B (TOS 20.11.85 GB)               *
X;*                         E1B (TOS 06.02.86 D)                *
X;*     for TOS 1.2 ff. automatically set                       *
X;*                                                             *
X;* THIS VERSION (4.xx) IGNORES ALL TOS KEYBOARD TABLES         *
X;* HAS A WARMBOOT on Ctrl-Alt-Del                              *
X;* HAS A COLDBOOT on Ctrl-Alt-rightShift-Del                   *
X;* AND INCLUDES A SCREEN SAVER                                 *
X;* Version for GST-Assembler                                   *
X;*                                                             *
X;***** (C) Roland Waldi *** 4.10-89/11 *************************
X
X          SECTION   MAIN
X          RORG      0
X          BRA       install
X
Xacia:
X          TST.W     W2
X          BEQ.S     L9
X          BCLR      #0,$FF820A
X          CLR.W     W2
XL9:       CLR.L     X3
X          MOVE.L    olacia,-(A7)
X          RTS
X
Xkbint:
X          MOVE.L    (A7)+,RTNadd   ;* return address
X          MOVE.L    TOSvec,A0
X          JSR       (A0)           ;* jump to TOS routine
X          MOVE.L    RTNadd,-(A7)   ;* return address
X          BRA.S     go
X
Xtimerint:
X          ADDQ.L    #1,X3
X          CMPI.L    #45000,X3      ;* 15 min
X          BLS.S     L3
XLOOP1N:   CMPI.B    #$80,$FF8207
X          BNE.S     LOOP1N
X          BSET      #0,$FF820A
X          ADDQ.W    #1,W2
XL3:
X          MOVE.L    (A7)+,RTNadd   ;* return address
X          MOVE.L    TMRvec,A0
X          JSR       (A0)           ;* call etv_timer
X          MOVE.L    RTNadd,-(A7)   ;* return address
Xgo:
X          MOVE.L    IOrec,A0
X          MOVE.L    (A0),A2        ;* get address of io-buffer
X          MOVE.W    8(A0),D1       ;* tail index
X          CMP.W     OLDtail,D1     ;* test if changed
X          BEQ.S     rturn
X          LEA       OLDtail,A1
X          MOVE.W    D1,(A1)        ;* save tail index at OLDtail
Xkbshadr:  MOVE.B    $E1B,D2        ;* get kbshifts (** TOS dependent **)
X          BTST      #2,D2          ;* CTRL set?
X          BEQ.S     noctrl         ;*   if not, translate
X          BTST      #3,D2          ;* ALT set?
X          BEQ.S     rturn          ;*   if not, return
X          MOVE.W    0(A2,D1.W),D0  ;* get...
X          AND.W     #$7F,D0        ;* ...key code
X          CMP.B     #$53,D0
X          BNE.S     nospecl
X          BTST      #0,D2          ;* right SHIFT set?
X          BNE.S     reset          ; C-A Del: Boot
X          CLR.L     $420           ; C-A-rS Del: Coldboot
X          CLR.L     $426
X          CLR.L     $43A
Xreset:    RESET
Xnospecl:
X          CLR.W     D0
X          BRA.S     store          ;* store 0
Xnoctrl:
X          MOVE.W    0(A2,D1.W),D0  ;* get...
X          AND.W     #$7F,D0        ;* ...key code
X          BTST      #3,D2          ;* ALT set?
X          BNE.S     altkeys        ;*   if 1
X          LEA       normal,A1      ;* get normal table
X          AND.B     #$13,D2        ;* test SHIFT l/r and CapsL
X          BEQ.S     goon           ;*   if none set
X          ADD.W     #128,D0        ;* use second table (SHIFT)
X          AND.B     #$03,D2        ;* only CapsLock set?
X          BNE.S     goon           ;* if not
X          ADD.W     #128,D0        ;* CapsLock table
X          BRA.S     goon
Xaltkeys:
X          LEA       ALTtabl,A1     ;* get translation table
X          AND.B     #$13,D2        ;* test SHIFT l/r and CapsL
X          BEQ.S     goon           ;* if none set
X          ADD.W     #128,D0        ;* use second table (SHIFT)
Xgoon:
X          MOVE.B    0(A1,D0.W),D0  ;* translate
Xstore:
X          MOVE.W    D0,2(A2,D1.W)  ;* store char code
Xrturn:
X          RTS
XTOSvec:
X          DC.L      0
XTMRvec:
X          DC.L      0
XRTNadd:
X          DC.L      0
XIOrec:
X          DC.L      0
XOLDtail:
X          DC.W      -1
Xtag:
X          DC.B      'K','B','E','X','T','/','R','W'
X;*
X;* here are the keyboard tables for normal, SHIFT,
X;*                                  and normal with CAPS LOCK
X;*                                  ALT, ALT&SHIFT
X;* you find them in the compiled program after the tag "KBEXT/RW"
X;*
X;* to change the keyboard layout, use the "normal" table as a
X;* guide for the keys (the layout is for a UK keyboard)
X;* and insert the ATARI/ASCII codes of the characters you want.
X;* NOTE:
X;* with ALT, the positions 02 ('1') ... 09 ('8') move to
X;* 78 ... 7F,
X;* and 0A ('9') ... 0D ('=') to 00 ... 03 (should be 80 ... 83)
X;* these rearrangements are done BY THE PROGRAM, so: fill the
X;* tables according to the normal keycode position.
X;*
Xnormal:
X          DC.B      $00,$1B,'1','2','3','4','5','6' ;* 00 Esc
X          DC.B      '7','8','9','0','-','=',$08,$09 ;* 08 BS,TAB
X          DC.B      'q','w','e','r','t','y','u','i' ;* 10
X          DC.B      'o','p',$5B,$5D,$0D,$00,'a','s' ;* 18 brackets,CR
X          DC.B      'd','f','g','h','j','k','l',';' ;* 20
X          DC.B      $27,'`',$00,'#','z','x','c','v' ;* 28 '
X          DC.B      'b','n','m',',','.','/',$00,$00 ;* 30
X          DC.B      $00,' ',$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,'-',$00,$00,$00,'+',$00 ;* 48
X          DC.B      $00,$00,$00,$7F,$00,$00,$00,$00 ;* 50 DEL
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $5C,$00,$00,'(',')','/','*','7' ;* 60 \
X          DC.B      '8','9','4','5','6','1','2','3' ;* 68
X          DC.B      '0','.',$0D,$00,$00,$00,$00,$00 ;* 70 Enter
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
Xshiftblk:
X          DC.B      $00,$1B,'!','@','#','$','%','^' ;* 00
X          DC.B      '&','*','(',')','_','+',$08,$09 ;* 08
X          DC.B      'Q','W','E','R','T','Y','U','I' ;* 10
X          DC.B      'O','P','{','}',$0D,$00,'A','S' ;* 18
X          DC.B      'D','F','G','H','J','K','L',':' ;* 20
X          DC.B      '"',$BA,$00,'~','Z','X','C','V' ;* 28
X          DC.B      'B','N','M','<','>','?',$00,$00 ;* 30
X          DC.B      $00,' ',$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,'-',$00,$00,$00,'+',$00 ;* 48
X          DC.B      $00,$00,$00,$7F,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      '|',$00,$00,'(',')','/','*','7' ;* 60
X          DC.B      '8','9','4','5','6','1','2','3' ;* 68
X          DC.B      '0','.',$0D,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
Xcapslock:
X          DC.B      $00,$1B,'1','2','3','4','5','6' ;* 00
X          DC.B      '7','8','9','0','-','=',$08,$09 ;* 08
X          DC.B      'Q','W','E','R','T','Y','U','I' ;* 10
X          DC.B      'O','P',$5B,$5D,$0D,$00,'A','S' ;* 18
X          DC.B      'D','F','G','H','J','K','L',';' ;* 20
X          DC.B      $27,'`',$00,'#','Z','X','C','V' ;* 28
X          DC.B      'B','N','M',',','.','/',$00,$00 ;* 30
X          DC.B      $00,' ',$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,'-',$00,$00,$00,'+',$00 ;* 48
X          DC.B      $00,$00,$00,$7F,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $5C,$00,$00,'(',')','/','*','7' ;* 60
X          DC.B      '8','9','4','5','6','1','2','3' ;* 68
X          DC.B      '0','.',$0D,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
XALTtabl:
X          DC.B      $00,$1B,$BB,$AB,$9C,$AC,$BF,$A9 ;* 00
X          DC.B      $BD,$F9,$F8,$B2,$7F,$F0,$00,$00 ;* 08
X          DC.B      $91,$C2,$89,$D5,$E7,$98,$81,$8B ;* 10
X          DC.B      $94,$E3,$C7,$F5,$00,$00,$84,$9E ;* 18
X          DC.B      $EB,$9F,$C4,$C6,$C0,$CC,$CD,$C8 ;* 20
X          DC.B      $CA,$CB,$00,$86,$B0,$B1,$87,$DE ;* 28
X          DC.B      $C3,$A4,$E6,$DB,$DC,$B3,$00,$00 ;* 30
X          DC.B      $00,$20,$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,$D9,$00,$00,$00,$D8,$00 ;* 48
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $B4,$00,$00,$E0,$E1,$ED,$EF,$A1 ;* 60
X          DC.B      $8C,$8D,$A0,$83,$85,$82,$88,$8A ;* 68
X          DC.B      $E9,$E5,$00,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $BB,$AB,$9C,$AC,$BF,$A9,$BD,$F9 ;* 78
X;* ALT & SHIFT
X          DC.B      $00,$1B,$AD,$B9,$DD,$9B,$F6,$AA ;* 00
X          DC.B      $BE,$FA,$A6,$A7,$F7,$F1,$00,$00 ;* 08
X          DC.B      $92,$D6,$EE,$D4,$D3,$9D,$9A,$EC ;* 10
X          DC.B      $99,$BC,$CF,$F4,$00,$00,$8E,$E4 ;* 18
X          DC.B      $C5,$CE,$E2,$C9,$C1,$D1,$D2,$D3 ;* 20
X          DC.B      $D4,$FF,$00,$8F,$B7,$B8,$80,$FB ;* 28
X          DC.B      $DF,$A5,$D0,$F3,$F2,$A8,$00,$00 ;* 30
X          DC.B      $00,$20,$00,$00,$00,$00,$00,$00 ;* 38
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 40
X          DC.B      $00,$00,$DA,$00,$00,$00,$D7,$00 ;* 48
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 50
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 58
X          DC.B      $B5,$00,$00,$AE,$AF,$E8,$B6,$A2 ;* 60
X          DC.B      $93,$95,$A3,$96,$97,$90,$FD,$FE ;* 68
X          DC.B      $EA,$FC,$00,$00,$00,$00,$00,$00 ;* 70
X          DC.B      $00,$00,$00,$00,$00,$00,$00,$00 ;* 78
X
X                                  ;* data for saver
XX3:       DC.L      0
XW2:       DC.W      0
Xolacia:   DC.L      0
X
Xpglength:
X          DC.L      0
Xinstall:
X          MOVEA.L   4(A7),A5       ;* basepage
X          LEA       pglength(PC),A0
X          LEA       install(PC),A1
X          MOVE.L    A1,D0
X          SUB.L     A5,D0          ;* calculate length
X          MOVE.L    D0,(A0)
X          MOVE.L    D0,-(A7)       ;* length
X          MOVE.L    A5,-(A7)       ;* start
X          CLR.W     -(A7)
X          MOVE.W    #$4A,-(A7)
X          TRAP      #1             ;* SETBLOCK, reserve storage
X          LEA       12(A7),A7
X          LEA       messg1(PC),A0  ;* display message
X          BSR       outp
X          CLR.W     -(A7)          ;* read file DEFAULT.KBD
X          PEA       file1(PC)
X          MOVE.W    #$3D,-(A7)     ;* open
X          TRAP      #1
X          ADDQ.L    #8,A7
X          TST.W     D0
X          BMI.S     nodefault
X          PEA       normal(PC)     ;* table address for read
X          MOVE.L    #384,-(A7)     ;* length
X          MOVE.W    D0,-(A7)       ;* handle
X          MOVE.W    #$3F,-(A7)     ;* read
X          TRAP      #1
X          LEA       12(A7),A7
X          MOVE.W    handle(PC),-(A7)
X          MOVE.W    #$3E,-(A7)     ;* close
X          TRAP      #1
X          ADDQ.L    #4,A7
X          LEA       file1(PC),A0   ;* display file1
X          BSR       outp
Xnodefault:
X          LEA       messg2(PC),A0  ;* display message
X          BSR       outp
X          CLR.W     -(A7)          ;* read file ALT.KBD
X          PEA       file2(PC)
X          MOVE.W    #$3D,-(A7)     ;* open
X          TRAP      #1
X          ADDQ.L    #8,A7
X          TST.W     D0
X          BMI.S     noaltfile
X          LEA       handle(PC),A0  ;* file handle
X          MOVE.W    D0,(A0)
X          PEA       ALTtabl(PC)    ;* table address for read
X          MOVE.L    #256,-(A7)     ;* length
X          MOVE.W    D0,-(A7)       ;* handle
X          MOVE.W    #$3F,-(A7)     ;* read
X          TRAP      #1
X          LEA       12(A7),A7
X          MOVE.W    handle(PC),-(A7)
X          MOVE.W    #$3E,-(A7)     ;* close
X          TRAP      #1
X          ADDQ.L    #4,A7
X          LEA       file2(PC),A0   ;* display file2
X          BSR       outp
Xnoaltfile:
X          LEA       ALTtabl(PC),A0 ;* rearrange ALT-Codes
X          MOVE.L    $02(A0),$78(A0)
X          MOVE.L    $06(A0),$7C(A0)
X          MOVE.L    $0A(A0),$00(A0)
X          MOVE.L    $082(A0),$0F8(A0) ;* same for ALT SHIFT
X          MOVE.L    $086(A0),$0FC(A0)
X          MOVE.L    $08A(A0),$080(A0)
X          MOVE.W    #1,-(A7)
X          MOVE.W    #14,-(A7)
X          TRAP      #14            ;* get iorec(1)
X          ADDQ.L    #4,A7
X          LEA       IOrec(PC),A0
X          MOVE.L    D0,(A0)        ;* save pointer to kbd-iorec
X          MOVE.W    #34,-(A7)
X          TRAP      #14            ;* Kbdvbase()
X          ADDQ.L    #2,A7
X          MOVE.L    D0,A1          ;* A1 = addr(kbdvbase)
X          LEA       TOSvec,A0
X          MOVE.L    32(A1),(A0)    ;* save interrupt routine address
X          LEA       kbint,A0
X          MOVE.L    A0,32(A1)      ;* install new interrupt vectors
X          CLR.L     -(A7)
X          MOVE.W    #$20,-(A7)
X          TRAP      #1             ;* Super
X          ADDQ.L    #6,A7
X          LEA       TMRvec,A0
X          MOVE.L    $400,(A0)      ;* save etv_timer routine address
X          LEA       timerint,A0
X          MOVE.L    A0,$400        ;* install new interrupt vector
X          LEA       olacia,A0
X          MOVE.L    $118,(A0)      ;* save ACIA interrupt vector
X          LEA       acia,A0
X          MOVE.L    A0,$118        ;* install new interrupt vector
X          MOVE.L    $4F2,A0        ;* get system address
X          CMPI.B    #2,3(A0)       ;* check subversion number
X          BLT.S     oldsys         ;* TOS < 1.2: keep address
X          MOVE.W    26(A0),kbshadr+2  ;* copy kbshift variable address
Xoldsys:
X          MOVE.L    D0,-(A7)
X          MOVE.W    #$20,-(A7)
X          TRAP      #1
X          ADDQ.L    #6,A7
X          LEA       messg3(PC),A0  ;* newline
X          BSR.S     outp
X          CLR.W     -(A7)          ;* return code
X          MOVE.L    pglength(PC),-(A7) ;* program length
X          MOVE.W    #$31,-(A7)     ;* Ptermres
X          TRAP      #1             ;* reserve storage and end
Xoutp:     MOVE.L    A0,-(A7)
X          MOVE.W    #$09,-(A7)
X          TRAP      #1             ;* print line
X          ADDQ.L    #6,A7
X          RTS                      ;* never reached
Xhandle:   DC.W      0
Xmessg1:   DC.B      $0D,$0A,'KBEXT v. 4.10 installing keyboard ',$00
Xmessg2:   DC.B      $0D,$0A,'------------- and ALT table       ',$00
Xmessg3:   DC.B      $0D,$0A,$00
Xfile1:    DC.B      $5C,'AUTO',$5C
X          DC.B      'DEFAULT.KBD',$00
Xfile2:    DC.B      $5C,'AUTO',$5C
X          DC.B      'ALT.KBD',$00
X          END
SHAR_EOF
chmod 0600 KBEXT4.ASM || echo "restore of KBEXT4.ASM fails"
exit 0