home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1998-02-27 | 14.7 KB | 313 lines |
- Mouse Key - A Keyboard mouse emulator
- Leo White, 1997
- Written as I couldn't find a SA compat mouse emulator elsewhere
- Sun 15th June 1997
- Sets up error handling
- " at line ";
- Sets up String variable
- title$ = "MouseKey"
- version$ = "0.02"
- author$ = "
- Leo White"
- date$ =
- $,20)
- date$ =
- date$,11)
- Sets up Number variables
- mouseV = &1A
- eventV = &10
- keyEvent = 11
- trigger = &5E
- mouseUp = &49
- mouseLeft = &5A
- mouseDown = &5B
- mouseRight = &5C
- mouseSelect = &3C
- mouseMenu = &3D
- mouseAdjust = &3E
- speed = 8
- Sets up Flags
- alt = %00000001
- up = %00000010
- right = %00000100
- left = %00001000
- down = %00010000
- select = %00100000
- menu = %01000000
- adjust = %10000000
- time = 0
- flags = 4
- OSWordBlock = 5
- xPosLow = 6
- xPosHigh = 7
- yPosLow = 8
- yPosHigh = 9
- Space for code
- start% 1024
- The assembly stuff
- pass = 4
- P%=0:O%=start%
- OPT pass
- 9D \**********************************************************\
- \ The module header
- ;+ EQUD 0 ; Start offset
- <4 EQUD init ; Initialisation offset
- =2 EQUD final ; Finalisation offset
- >. EQUD 0 ; Service request
- ?5 EQUD title ; Offset to title string
- @4 EQUD help ; Offset to help string
- A1 EQUD 0 ; Offset to commands
- CD \**********************************************************\
- .title
- E& ; Title string if the module
- EQUS title$+
- ALIGN
- ID \**********************************************************\
- .help
- K4 ; Sets up the help string for *Help Module
- L: EQUS title$+
- 9+version$+" ("+date$+") "+author$
- EQUB 0
- ALIGN
- PD \**********************************************************\
- .init
- RD ; Initialises the module, sets up workspace if needed etc.
- S STMFD R13!,{R0-R3,R14}
- U? MOV R0,#6 ; OS_Module code for claim
- VE MOV R3,#12 ; Number Of Bytes (Word Aligned)
- W4 SWI "XOS_Module" ; Claims Memory
- XI BVS error ; If there was an error, then return
- YG STR R2,[R12] ; Stores pointer to address in R12
- Z9 MOV R0,#0 ; Zero to initialise
- [9 STR R0,[R2,#flags] ; Initialises memory
- \9 STR R0,[R2,#time] ; Initialises memory
- ^4 MOV R0,#mouseV ; MouseV number
- _; ADR R1,mouseHandler ; Routine to be called
- `J MOV R2,R12 ; Value to be passed when we close it
- a? SWI "XOS_Claim" ; Claims The MouseV Vector
- bG BVS error ; If there was an error, then quit
- dH MOV R0,#14 ; Sets up OS_Byte enable event code
- e= MOV R1,#10 ; Specifies MouseV event
- f> SWI "XOS_Byte" ; Enables MouseKey Events
- gG BVS error ; If there was an error, then quit
- i4 MOV R0,#eventV ; EventV number
- j; ADR R1,eventHandler ; Routine to be called
- kR MOV R2,R12 ; Value to be passed when we want to close it
- l? SWI "XOS_Claim" ; Claims The MouseV Vector
- mG BVS error ; If there was an error, then quit
- oH MOV R0,#14 ; Sets up OS_Byte enable event code
- pB MOV R1,#11 ; Specifies Key Up/Down event
- q@ SWI "XOS_Byte" ; Enables Key Up/Down Event
- rL ; If error, then it just drops straight
- s6 ; through anyway.
- .error
- v6 LDMFD R13!,{R0-R3,PC} ; Exits procedure
- xD \**********************************************************\
- y3 ; Finalisation routine. Unsets Events etc.
- .final
- { STMFD R13!,{R0-R2,R14}
- }= MOV R0,#mouseV ; Specifies MouseV event
- ~B ADR R1,mouseHandler ; Pointer to the routine used
- J MOV R2,R12 ; Value passed when we enabled MouseV
- @ SWI "XOS_Release" ; Releases the MouseV event
- O MOV R0,#13 ; Sets up OS_Byte call for disabling event
- = MOV R1,#10 ; Specifies MouseV event
- < SWI "XOS_Byte" ; Disables MouseV event
- = MOV R0,#eventV ; Specifies EventV event
- B ADR R1,eventHandler ; Pointer to the routine used
- J MOV R2,R12 ; Value passed when we enabled MouseV
- @ SWI "XOS_Release" ; Releases the MouseV event
- O MOV R0,#13 ; Sets up OS_Byte call for disabling event
- = MOV R1,#11 ; Specifies MouseV event
- < SWI "XOS_Byte" ; Disables MouseV event
- = MOV R0,#7 ; OS_Module Release Code
- ; LDR R2,[R12] ; Move pointer into R2
- 6 SWI "XOS_Module" ; Releases Memory
- LDMFD R13!,{R0-R2,PC}
- F \**********************************************************\
- > ; This is the bit of code that will handle the mouse
- .mouseHandler
- STMFD R13!,{R5}
- > LDR R12,[R12] ; Points To Workspace
- ; LDRB R5,[R12,#flags] ; Puts flags in R5
- G TST R5,#alt ; Checks if Alt key is pressed
- LDMFD R13!,{R5}
- ;
- Q PC,R14 ; If not, then return
- H \**********************************************************\
- 3 ; Checks If Time Has Incremented Enough
- & STMFD R13!,{R10-R12,R14}
- ? SWI "OS_ReadMonotonicTime" ; Reads Time Into R0
- K LDR R1,[R12,#time] ; Sets R1 As pointer to old time
- D SUB R0,R0,R1 ; Current Time - Old Time
- < CMP R0,#1 ; Compares answer
- A BLT postProcess ; Jumps To PostProcess
- H \**********************************************************\
- , ; Pre Processing stuff goes here
- 1 ; Reads in The Current Mouse Position
- = MOV R0,#4 ; 4 = Read mouse Pos
- E MOV R1,R12 ; Loads address of workspace
- D ADD R1,R1,#OSWordBlock ; Sets R1 to Point To block
- = STRB R0,[R1] ; Puts Byte In Block
- 9 MOV R0,#21 ; OSWord 21 Call
- B SWI "XOS_Word" ; Reads In Mouse Position
- ( ; Adjusts the Mouse position
- # LDR R5,[R12,#flags]
- ? TST R5,#up ; Checks if Up pressed
- ? BLNE movePointerUp ; Moves The Pointer Up
- A TST R5,#down ; Checks if Down pressed
- A BLNE movePointerDown ; Moves The Pointer Down
- A TST R5,#left ; Checks if Left pressed
- A BLNE movePointerLeft ; Moves The Pointer Left
- B TST R5,#right ; Checks if Right pressed
- B BLNE movePointerRight ; Moves The Pointer Right
- - ; Sets The Current Mouse Position
- < MOV R0,#3 ; 3 = Set mouse Pos
- J MOV R1,R12 ; Loads workspace address into R1
- C ADD R1,R1,#OSWordBlock ; Points to start of block
- = STRB R0,[R1] ; Puts Byte In Block
- 9 MOV R0,#21 ; OSWord 21 Call
- A SWI "XOS_Word" ; Sets In Mouse Position
- H \**********************************************************\
- = ; Sets Up pointers To Point to Post Precssing Bit
- .postProcess
- F MOV R12,R15 ; Stores PC+8 Or PC+12 In R12
- E ADD R12,R12,#12 ; Adds an offset of 12 to PC
- > STMFD R13!,{R12} ; Stores R12 On Stack
- G ADD R12,R13,#4 ; Points Stack at 1 Address In
- E LDMIA R12,{R10-R12,R15} ; Loads Stuff Onto The Stack
- H MOV R0,R0 ; A No-op to handle StrongARM's
- G LDR R12,[R13,#8] ; Gets R12 back from the stack
- H \**********************************************************\
- / ; The Post processing bits are here
- = ; This is where we check what buttons are pressed
- ; LDRB R5,[R12,#flags] ; Puts flags in R5
- F TST R5,#adjust ; Checks if adjust is pressed
- K
- RNE R2,R2,#1 ; Sets Button press to adjust click
- D TST R5,#menu ; Checks if menu is pressed
- I
- RNE R2,R2,#2 ; Sets Button press to menu click
- F TST R5,#select ; Checks if select is pressed
- K
- RNE R2,R2,#4 ; Sets Button press to select click
- D LDMFD R13!,{R10-R12,R14,PC} ; Claims Vector and returns
- F \**********************************************************\
- ) ; Code To Change Mouse Position
- .movePointerUp
- $ STMFD R13!,{R0-R5,R14}
- E BL setYValues ; Sets Up Pointers To Memory
- < B incrementValue ; Increments Values
- F \**********************************************************\
- ) ; Code To Change Mouse Position
- .movePointerRight
- $ STMFD R13!,{R0-R5,R14}
- ; BL setXValues ; Sets up X Values
- .incrementValue
- 8 ADD R0,R0,#speed ; Increments R0
- C CMP R0,#255 ; Checks if value too high
- 7 SUBGT R0,R0,#255 ; Sets it to 0
- E ADDGT R3,R3,#1 ; Increments X High Position
- D B storeAndReturn ; Stores Values And Returns
- F \**********************************************************\
- ) ; Code To Change Mouse Position
- .movePointerDown
- $ STMFD R13!,{R0-R5,R14}
- E BL setYValues ; Sets Up Pointers To Memory
- @ B decrementValues ; Decrements the Values
- F \**********************************************************\
- ) ; Code To Change Mouse Position
- .movePointerLeft
- # STMFD R13!,{R0-R5,R14}
- < BL setXValues ; Sets up X Values
- .decrementValues
- 9 SUB R0,R0,#speed ; Decrements R0
- D CMP R0,#0 ; Checks if value too high
- 8 ADDLT R0,R0,#255 ; Sets it to 0
- F SUBLT R3,R3,#1 ; Decrements X High Position
- .storeAndReturn
- !F STRB R0,[R1] ; Writes Back x Low Position
- "G STRB R3,[R2] ; Writes Back x High Position
- $9 SWI "OS_ReadMonotonicTime" ; Reads In Time
- %! STR R0,[R12,#time]
- &" LDMFD R13!,{R0-R5,PC}
- (F \**********************************************************\
- )$ ; Sets Up Y Pointer Values
- .setYValues
- +# ADD R1,R12,#yPosLow
- ,? LDRB R0,[R1] ; Loads Value into R0
- -$ ADD R2,R12,#yPosHigh
- .C LDRB R3,[R2] ; Load High Y Pos into R3
- MOV PC,R14
- 2F \**********************************************************\
- 3$ ; Sets Up X Pointer Values
- .setXValues
- 5# ADD R1,R12,#xPosLow
- 6C LDRB R0,[R1] ; Loads Low X Pos into R0
- 7$ ADD R2,R12,#xPosHigh
- 8C LDRB R3,[R2] ; Load High X Pos into R3
- MOV PC,R14
- <F \**********************************************************\
- =J ; This is the bit of code that will handle the key up/down event
- >N ; Note, Currently I don't claim the event, so keypresses R passed on
- .eventHandler
- @J TEQ R0,#keyEvent ; Checks if its a key Up/Down event
- AD MOVNE PC,R14 ; We don't want it, so return
- C# STMFD R13!,{R0-R5,R14}
- EC LDR R12,[R12] ; Loads In Workspace Pointer
- G? LDRB R4,[R12,#flags] ; Stores our flags in R4
- I4 \ By default, we are in a key down event
- J< TEQ R2,#trigger ; Is trigger pressed?
- K:
- Q R5,#alt ; Sets alt key in flag
- L: BEQ exitHandler ; Exits The Routine
- N, \ Fall through to check next key
- O< TEQ R2,#mouseUp ; Is mouseUp pressed?
- P9
- Q R5,#up ; Sets up key in flag
- Q: BEQ exitHandler ; Exits The Routine
- S, \ Fall through to check next key
- T> TEQ R2,#mouseLeft ; Is mouseLeft pressed?
- U;
- Q R5,#left ; Sets left key in flag
- V: BEQ exitHandler ; Exits The Routine
- X, \ Fall through to check next key
- Y> TEQ R2,#mouseDown ; Is mouseDown pressed?
- Z;
- Q R5,#down ; Sets down key in flag
- [: BEQ exitHandler ; Exits The Routine
- ], \ Fall through to check next key
- ^? TEQ R2,#mouseRight ; Is mouseRight pressed?
- _<
- Q R5,#right ; Sets right key in flag
- `: BEQ exitHandler ; Exits The Routine
- b, \ Fall through to check next key
- c@ TEQ R2,#mouseSelect ; Is mouseSelect pressed?
- d=
- Q R5,#select ; Sets select key in flag
- e: BEQ exitHandler ; Exits The Routine
- g, \ Fall through to check next key
- h> TEQ R2,#mouseMenu ; Is mouseMenu pressed?
- i;
- Q R5,#menu ; Sets menu key in flag
- j: BEQ exitHandler ; Exits The Routine
- l, \ Fall through to check next key
- m@ TEQ R2,#mouseAdjust ; Is mouseAdjust pressed?
- n=
- Q R5,#adjust ; Sets adjust key in flag
- o: BEQ exitHandler ; Exits The Routine
- q) \ If Not matched, then return
- rK LDMNEFD R13!,{R0-R5,PC} ; Exits routine regardless of result
- .exitHandler
- uG TEQ R1,#0 ; Checks if it is a key up event
- v> BICEQ R4,R4,R5 ; If key Up, Then Clear
- w:
- RNE R4,R4,R5 ; Otherwise, set Bit
- y4 STRB R4,[R12,#flags] ; Saves flags
- zK LDMFD R13!,{R0-R5,PC} ; Exits routine regardless of result
- pass
- Saves Module To Disc
- "OS_File",10,"MKey",&FFA,,start%,O%
- "Module Saved"
- End Of Program
-