home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / misc / mousekey / MouseKey (.txt) < prev   
Encoding:
RISC OS BBC BASIC V Source  |  1998-02-27  |  14.7 KB  |  313 lines

  1.  Mouse Key - A Keyboard mouse emulator
  2. Leo White, 1997
  3.  Written as I couldn't find a SA compat mouse emulator elsewhere
  4.  Sun 15th June 1997
  5.  Sets up error handling
  6.  " at line ";
  7.  Sets up String variable
  8. title$   = "MouseKey"
  9. version$ = "0.02"
  10. author$  = "
  11.  Leo White"
  12. date$    = 
  13. $,20)
  14. date$    = 
  15. date$,11)
  16.  Sets up Number variables
  17. mouseV      = &1A
  18. eventV      = &10
  19. keyEvent    = 11
  20. trigger     = &5E
  21. mouseUp     = &49
  22. mouseLeft   = &5A
  23. mouseDown   = &5B
  24. mouseRight  = &5C
  25. mouseSelect = &3C
  26. mouseMenu   = &3D
  27. mouseAdjust = &3E
  28. speed       = 8
  29.  Sets up Flags
  30. alt    = %00000001
  31. up     = %00000010
  32. right  = %00000100
  33. left   = %00001000
  34. down   = %00010000
  35. select = %00100000
  36. menu   = %01000000
  37. adjust = %10000000
  38. time        = 0
  39. flags       = 4
  40. OSWordBlock = 5
  41. xPosLow     = 6
  42. xPosHigh    = 7
  43. yPosLow     = 8
  44. yPosHigh    = 9
  45.  Space for code
  46.  start% 1024
  47.  The assembly stuff
  48.  pass = 4 
  49.   P%=0:O%=start%
  50.     OPT pass
  51. 9D    \**********************************************************\
  52.     \ The module header
  53. ;+    EQUD 0               ; Start offset
  54. <4    EQUD init            ; Initialisation offset
  55. =2    EQUD final           ; Finalisation offset
  56. >.    EQUD 0               ; Service request
  57. ?5    EQUD title           ; Offset to title string
  58. @4    EQUD help            ; Offset to help string
  59. A1    EQUD 0               ; Offset to commands
  60. CD    \**********************************************************\
  61.     .title
  62. E&      ; Title string if the module
  63.       EQUS title$+
  64.       ALIGN
  65. ID    \**********************************************************\
  66.     .help
  67. K4      ; Sets up the help string for *Help Module
  68. L:      EQUS title$+
  69. 9+version$+" ("+date$+") "+author$ 
  70.       EQUB 0
  71.       ALIGN
  72. PD    \**********************************************************\
  73.     .init
  74. RD      ; Initialises the module, sets up workspace if needed etc.
  75. S       STMFD R13!,{R0-R3,R14}
  76. U?      MOV   R0,#6                ; OS_Module code for claim
  77. VE      MOV   R3,#12               ; Number Of Bytes (Word Aligned)
  78. W4      SWI   "XOS_Module"         ; Claims Memory
  79. XI      BVS   error                ; If there was an error, then return
  80. YG      STR   R2,[R12]             ; Stores pointer to address in R12
  81. Z9      MOV   R0,#0                ; Zero to initialise
  82. [9      STR   R0,[R2,#flags]       ; Initialises memory
  83. \9      STR   R0,[R2,#time]        ; Initialises memory
  84. ^4      MOV   R0,#mouseV           ; MouseV number
  85. _;      ADR   R1,mouseHandler      ; Routine to be called
  86. `J      MOV   R2,R12               ; Value to be passed when we close it
  87. a?      SWI   "XOS_Claim"          ; Claims The MouseV Vector
  88. bG      BVS   error                ; If there was an error, then quit
  89. dH      MOV   R0,#14               ; Sets up OS_Byte enable event code
  90. e=      MOV   R1,#10               ; Specifies MouseV event
  91. f>      SWI   "XOS_Byte"           ; Enables MouseKey Events
  92. gG      BVS   error                ; If there was an error, then quit
  93. i4      MOV   R0,#eventV           ; EventV number
  94. j;      ADR   R1,eventHandler      ; Routine to be called
  95. kR      MOV   R2,R12               ; Value to be passed when we want to close it
  96. l?      SWI   "XOS_Claim"          ; Claims The MouseV Vector
  97. mG      BVS   error                ; If there was an error, then quit
  98. oH      MOV   R0,#14               ; Sets up OS_Byte enable event code
  99. pB      MOV   R1,#11               ; Specifies Key Up/Down event
  100. q@      SWI   "XOS_Byte"           ; Enables Key Up/Down Event
  101. rL                                 ; If error, then it just drops straight
  102. s6                                 ; through anyway.
  103.     .error
  104. v6      LDMFD R13!,{R0-R3,PC}      ; Exits procedure
  105. xD    \**********************************************************\
  106. y3    ; Finalisation routine.  Unsets Events etc.
  107.     .final
  108. {       STMFD R13!,{R0-R2,R14}
  109. }=      MOV   R0,#mouseV           ; Specifies MouseV event
  110. ~B      ADR   R1,mouseHandler      ; Pointer to the routine used
  111. J      MOV   R2,R12               ; Value passed when we enabled MouseV
  112. @      SWI   "XOS_Release"        ; Releases the MouseV event
  113. O      MOV   R0,#13               ; Sets up OS_Byte call for disabling event
  114. =      MOV   R1,#10               ; Specifies MouseV event
  115. <      SWI   "XOS_Byte"           ; Disables MouseV event
  116. =      MOV   R0,#eventV           ; Specifies EventV event
  117. B      ADR   R1,eventHandler      ; Pointer to the routine used
  118. J      MOV   R2,R12               ; Value passed when we enabled MouseV
  119. @      SWI   "XOS_Release"        ; Releases the MouseV event
  120. O      MOV   R0,#13               ; Sets up OS_Byte call for disabling event
  121. =      MOV   R1,#11               ; Specifies MouseV event
  122. <      SWI   "XOS_Byte"           ; Disables MouseV event
  123. =      MOV   R0,#7                ; OS_Module Release Code
  124. ;      LDR   R2,[R12]             ; Move pointer into R2
  125. 6      SWI   "XOS_Module"         ; Releases Memory
  126.       LDMFD R13!,{R0-R2,PC}
  127. F      \**********************************************************\
  128. >      ; This is the bit of code that will handle the mouse
  129.       .mouseHandler
  130.         STMFD    R13!,{R5}
  131. >        LDR      R12,[R12]           ; Points To Workspace
  132. ;        LDRB     R5,[R12,#flags]     ; Puts flags in R5
  133. G        TST      R5,#alt             ; Checks if Alt key is pressed
  134.         LDMFD    R13!,{R5}
  135. ;        
  136. Q    PC,R14              ; If not, then return
  137. H        \**********************************************************\
  138. 3        ; Checks If Time Has Incremented Enough
  139. &        STMFD   R13!,{R10-R12,R14}
  140. ?        SWI     "OS_ReadMonotonicTime" ; Reads Time Into R0
  141. K        LDR     R1,[R12,#time]         ; Sets R1 As pointer to old time
  142. D        SUB     R0,R0,R1               ; Current Time - Old Time
  143. <        CMP     R0,#1                  ; Compares answer
  144. A        BLT     postProcess            ; Jumps To PostProcess
  145. H        \**********************************************************\
  146. ,        ; Pre Processing stuff goes here
  147. 1        ; Reads in The Current Mouse Position
  148. =        MOV     R0,#4                ; 4 = Read mouse Pos
  149. E        MOV     R1,R12               ; Loads address of workspace
  150. D        ADD     R1,R1,#OSWordBlock   ; Sets R1 to Point To block
  151. =        STRB    R0,[R1]              ; Puts Byte In Block
  152. 9        MOV     R0,#21               ; OSWord 21 Call
  153. B        SWI     "XOS_Word"           ; Reads In Mouse Position
  154. (        ; Adjusts the Mouse position
  155. #        LDR     R5,[R12,#flags]
  156. ?        TST     R5,#up               ; Checks if Up pressed
  157. ?        BLNE    movePointerUp        ; Moves The Pointer Up
  158. A        TST     R5,#down             ; Checks if Down pressed
  159. A        BLNE    movePointerDown      ; Moves The Pointer Down
  160. A        TST     R5,#left             ; Checks if Left pressed
  161. A        BLNE    movePointerLeft      ; Moves The Pointer Left
  162. B        TST     R5,#right            ; Checks if Right pressed
  163. B        BLNE    movePointerRight     ; Moves The Pointer Right
  164. -        ; Sets The Current Mouse Position
  165. <        MOV     R0,#3                ; 3 = Set mouse Pos
  166. J        MOV     R1,R12               ; Loads workspace address into R1
  167. C        ADD     R1,R1,#OSWordBlock   ; Points to start of block
  168. =        STRB    R0,[R1]              ; Puts Byte In Block
  169. 9        MOV     R0,#21               ; OSWord 21 Call
  170. A        SWI     "XOS_Word"           ; Sets In Mouse Position
  171. H        \**********************************************************\
  172. =        ; Sets Up pointers To Point to Post Precssing Bit
  173.       .postProcess
  174. F        MOV     R12,R15              ; Stores PC+8 Or PC+12 In R12
  175. E        ADD     R12,R12,#12          ; Adds an offset of 12 to PC
  176. >        STMFD   R13!,{R12}           ; Stores R12 On Stack
  177. G        ADD     R12,R13,#4           ; Points Stack at 1 Address In
  178. E        LDMIA   R12,{R10-R12,R15}    ; Loads Stuff Onto The Stack
  179. H        MOV     R0,R0                ; A No-op to handle StrongARM's
  180. G        LDR     R12,[R13,#8]         ; Gets R12 back from the stack
  181. H        \**********************************************************\
  182. /        ; The Post processing bits are here
  183. =        ; This is where we check what buttons are pressed
  184. ;        LDRB     R5,[R12,#flags]     ; Puts flags in R5
  185. F        TST      R5,#adjust          ; Checks if adjust is pressed
  186. K        
  187. RNE    R2,R2,#1            ; Sets Button press to adjust click
  188. D        TST      R5,#menu            ; Checks if menu is pressed
  189. I        
  190. RNE    R2,R2,#2            ; Sets Button press to menu click
  191. F        TST      R5,#select          ; Checks if select is pressed
  192. K        
  193. RNE    R2,R2,#4            ; Sets Button press to select click
  194. D        LDMFD R13!,{R10-R12,R14,PC}  ; Claims Vector and returns
  195. F      \**********************************************************\
  196. )      ; Code To Change Mouse Position
  197.       .movePointerUp
  198. $        STMFD   R13!,{R0-R5,R14}
  199. E        BL      setYValues           ; Sets Up Pointers To Memory
  200. <        B       incrementValue       ; Increments Values
  201. F      \**********************************************************\
  202. )      ; Code To Change Mouse Position
  203.       .movePointerRight
  204. $        STMFD   R13!,{R0-R5,R14}
  205. ;        BL      setXValues           ; Sets up X Values
  206.       .incrementValue
  207. 8        ADD     R0,R0,#speed         ; Increments R0
  208. C        CMP     R0,#255              ; Checks if value too high
  209. 7        SUBGT   R0,R0,#255           ; Sets it to 0
  210. E        ADDGT   R3,R3,#1             ; Increments X High Position
  211. D        B       storeAndReturn       ; Stores Values And Returns
  212. F      \**********************************************************\
  213.     )      ; Code To Change Mouse Position
  214.       .movePointerDown
  215. $        STMFD   R13!,{R0-R5,R14}
  216. E        BL      setYValues           ; Sets Up Pointers To Memory
  217. @        B       decrementValues      ; Decrements the Values
  218. F      \**********************************************************\
  219. )      ; Code To Change Mouse Position
  220.       .movePointerLeft
  221. #        STMFD  R13!,{R0-R5,R14}
  222. <        BL     setXValues             ; Sets up X Values
  223.       .decrementValues
  224. 9        SUB    R0,R0,#speed           ; Decrements R0
  225. D        CMP    R0,#0                  ; Checks if value too high
  226. 8        ADDLT  R0,R0,#255             ; Sets it to 0
  227. F        SUBLT  R3,R3,#1               ; Decrements X High Position
  228.       .storeAndReturn
  229. !F        STRB   R0,[R1]                ; Writes Back x Low Position
  230. "G        STRB   R3,[R2]                ; Writes Back x High Position
  231. $9        SWI    "OS_ReadMonotonicTime" ; Reads In Time
  232. %!        STR    R0,[R12,#time]
  233. &"        LDMFD  R13!,{R0-R5,PC}
  234. (F      \**********************************************************\
  235. )$      ; Sets Up Y Pointer Values
  236.       .setYValues
  237. +#        ADD     R1,R12,#yPosLow
  238. ,?        LDRB    R0,[R1]               ; Loads Value into R0
  239. -$        ADD     R2,R12,#yPosHigh
  240. .C        LDRB    R3,[R2]               ; Load High Y Pos into R3
  241.         MOV     PC,R14
  242. 2F      \**********************************************************\
  243. 3$      ; Sets Up X Pointer Values
  244.       .setXValues
  245. 5#        ADD     R1,R12,#xPosLow
  246. 6C        LDRB    R0,[R1]               ; Loads Low X Pos into R0
  247. 7$        ADD     R2,R12,#xPosHigh
  248. 8C        LDRB    R3,[R2]               ; Load High X Pos into R3
  249.         MOV     PC,R14
  250. <F      \**********************************************************\
  251. =J      ; This is the bit of code that will handle the key up/down event
  252. >N      ; Note, Currently I don't claim the event, so keypresses R passed on
  253.       .eventHandler
  254. @J        TEQ    R0,#keyEvent        ; Checks if its a key Up/Down event
  255. AD        MOVNE  PC,R14              ; We don't want it, so return
  256. C#        STMFD  R13!,{R0-R5,R14}
  257. EC        LDR    R12,[R12]           ; Loads In Workspace Pointer
  258. G?        LDRB   R4,[R12,#flags]     ; Stores our flags in R4
  259. I4        \ By default, we are in a key down event
  260. J<        TEQ     R2,#trigger        ; Is trigger pressed?
  261. K:        
  262. Q   R5,#alt            ; Sets alt key in flag
  263. L:        BEQ     exitHandler        ; Exits The Routine
  264. N,        \ Fall through to check next key
  265. O<        TEQ     R2,#mouseUp        ; Is mouseUp pressed?
  266. P9        
  267. Q   R5,#up             ; Sets up key in flag
  268. Q:        BEQ     exitHandler        ; Exits The Routine
  269. S,        \ Fall through to check next key
  270. T>        TEQ     R2,#mouseLeft      ; Is mouseLeft pressed?
  271. U;        
  272. Q   R5,#left           ; Sets left key in flag
  273. V:        BEQ     exitHandler        ; Exits The Routine
  274. X,        \ Fall through to check next key
  275. Y>        TEQ     R2,#mouseDown      ; Is mouseDown pressed?
  276. Z;        
  277. Q   R5,#down           ; Sets down key in flag
  278. [:        BEQ     exitHandler        ; Exits The Routine
  279. ],        \ Fall through to check next key
  280. ^?        TEQ     R2,#mouseRight     ; Is mouseRight pressed?
  281. _<        
  282. Q   R5,#right          ; Sets right key in flag
  283. `:        BEQ     exitHandler        ; Exits The Routine
  284. b,        \ Fall through to check next key
  285. c@        TEQ     R2,#mouseSelect    ; Is mouseSelect pressed?
  286. d=        
  287. Q   R5,#select         ; Sets select key in flag
  288. e:        BEQ     exitHandler        ; Exits The Routine
  289. g,        \ Fall through to check next key
  290. h>        TEQ     R2,#mouseMenu      ; Is mouseMenu pressed?
  291. i;        
  292. Q   R5,#menu           ; Sets menu key in flag
  293. j:        BEQ     exitHandler        ; Exits The Routine
  294. l,        \ Fall through to check next key
  295. m@        TEQ     R2,#mouseAdjust    ; Is mouseAdjust pressed?
  296. n=        
  297. Q   R5,#adjust         ; Sets adjust key in flag
  298. o:        BEQ     exitHandler        ; Exits The Routine
  299. q)        \ If Not matched, then return
  300. rK        LDMNEFD R13!,{R0-R5,PC}    ; Exits routine regardless of result
  301.      .exitHandler
  302. uG        TEQ    R1,#0               ; Checks if it is a key up event
  303. v>        BICEQ  R4,R4,R5            ; If key Up, Then Clear
  304. w:        
  305. RNE  R4,R4,R5            ; Otherwise, set Bit
  306. y4        STRB    R4,[R12,#flags]    ; Saves flags
  307. zK        LDMFD   R13!,{R0-R5,PC}    ; Exits routine regardless of result
  308.  pass
  309.  Saves Module To Disc
  310.  "OS_File",10,"MKey",&FFA,,start%,O%
  311.  "Module Saved"
  312.  End Of Program
  313.