;;ObjAsm module source file for KeyMap module

;;set up register names
R0  RN 0
R1  RN 1
R2  RN 2
R3  RN 3
R4  RN 4
R5  RN 5
R6  RN 6
R7  RN 7
R8  RN 8
R9  RN 9
R10 RN 10
R11 RN 11
R12 RN 12
R13 RN 13
R14 RN 14
PC  RN 15

;;set up SWI names
XModule                * &2001E
XRegisterPostFilter    * &62641
XDeRegisterPostFilter  * &62643

;;set up constants
overflow    * &10000000
chunk       * &D01C0

 
 AREA code,CODE
  
 ENTRY


tit         * title-start
hel         * help-start
swis        * switable-start
init        * initial-start
fin         * final-start
swines      * swinames-start
 
start
 DCD 0,init,fin,0             ;)
 DCD tit,hel,0                ;) module header
 DCD chunk,swis,swines        ;)
 
title
 = "KeyMap",0
 
help
 = "KeyMap Support",9,"1.00 (25 Jan 1996)",0
 ALIGN
 
swinames
 = "KeyMap",0                 ;SWI base name
 = "FilterOn",0               ;SWI name list
 = "FilterOff",0,0
 ALIGN
 
switable
 CMP R11,#2
 ADDLO PC,PC,R11,LSL#2
 B unknown
 B filteron
 B filteroff
 
unknown
 MOVS PC,R14
 
 
initial                       ;module initialisation code
 STMFD R13!,{R14}
 MOV R0,#6
 MOV R3,#96
 SWI XModule                  ;claim 96 bytes of workspace
                              ;mapped codes are placed in workspace
                              ;by front end application
 STR R2,[R12]
 LDMFD R13!,{PC}

   
final                         ;module finalisation code
 STMFD R13!,{R14}
 MOV R0,#7
 LDR R2,[R12]
 SWI XModule                  ;release workspace
 LDMFD R13!,{PC}
 

filteron                      ;called when SWI "KeyMap_FilterOn" received
 STMFD R13!,{R0-R5,R14}
 ADR R0,title                 ;set up registers for filter call
 ADR R1,filter                ;address of filter routine
 LDR R2,[R12]                 ;workspace pointer to be passed in R12
 LDR R4,value                 ;value of filter mask
                              ;task handle in R3 is passed by calling task
 SWI XRegisterPostFilter      ;set up post-filter
 LDMFD R13!,{R0-R5,PC}^


filteroff                     ;called when SWI "KeyMap_FilterOff" received
 STMFD R13!,{R0-R5,R14}
 ADR R0,title                 ;set up registers as for filteron routine
 ADR R1,filter
 LDR R2,[R12]
 LDR R4,value
 SWI XDeRegisterPostFilter
 LDMFD R13!,{R0-R5,PC}^


filter                        ;filter routine called when filtered task
                              ;receives keypress event
 STMFD R13!,{R0,R14}
 LDR R0,[R1,#24]              ;get ASCII code of key pressed
 CMP R0,#32
 LDMLTFD R13!,{R0,PC}^        ;ignore if less than 32
 CMP R0,#126
 LDMGTFD R13!,{R0,PC}^        ;ignore if greater than 126
 SUB R0,R0,#32
 LDRB R0,[R12,R0]             ;get currently mapped code for that key
                              ;from workspace
 STR R0,[R1,#24]              ;replace original key code with new one
 LDMFD R13!,{R0,PC}^


value
 DCD &FFFFFEFF                ;mask value - masks out all bits except
                              ;bit 8 (keypress)


 END 
 