mouse 10.1 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; > $.Source.PMF.Mouse

; Mouse driving code

; Author:       Steve Cormie
; Started:      24-Feb-93

; Change history:
;
; Date          Who     Description
; ----          ---     -----------
; 24-Feb-93     SMC     Created.

; *****************************************************************************
;
;        Mouse initialisation
;
MouseInit
        Push    "lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
34
        LDR     r11, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

        MOV     r0, #MouseStepCMOS      ; setup mouse multipliers from CMOS
        BL      Read
        MOV     r0, r0, LSL #24         ; sign extend it
        MOVS    r0, r0, ASR #24
        MOVEQ   r0, #1                  ; if would be zero, set to 1
        STR     r0, MouseXMult
        STR     r0, MouseYMult

        MOV     r0, #0
        STRB    r0, MouseButtons

        MOV     r0, #MouseCMOS
        BL      Read
        STRB    r0, MouseType

        Pull    "pc"

; *****************************************************************************
;
;       MouseButtonChange - Called by keyboard handler when mouse button change
;
; in:   R0 = state of buttons (bit0=R, bit1=C, bit2=L)
;       R11 -> KeyWorkSpace
;

MouseButtonChange ROUT
        Push    "R0-R5, R12, R14"

        VDWS    WsPtr
        STRB    R0, MouseButtons        ; save it for ReadMouse calls
        MOV     R3, R0

        LDR     R1, MouseX
        LDR     R0, [WsPtr, #OrgX]
        SUB     R1, R1, R0              ; mouse X

        LDR     R2, MouseY
        LDR     R0, [WsPtr, #OrgY]
        SUB     R2, R2, R0              ; mouse Y

Jeffrey Lee's avatar
Jeffrey Lee committed
76
        LDR     R4, =ZeroPage
Neil Turton's avatar
Neil Turton committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        LDR     R4, [R4, #MetroGnome]   ; use monotonic variable now

        MOV     R0, #Event_Mouse
        BL      OSEVEN

; Use buffer manager's 'block insert' function

; TMD 26-Feb-93: Fix bug - if X is negative, Y would be inserted in the buffer as -1

        LDR     R0, MouseX              ; 16 bits, sign-extended to 32 bits
        MOV     R0, R0, LSL #16
        LDR     R1, MouseY              ; ditto
        MOV     R1, R1, LSL #16
        ORR     R0, R1, R0, LSR #16     ; combine, having knocked off the troublesome bits
        ORR     R1, R3, R4, LSL #8      ; R1 = Combined 8bit buttons and 24 LSB's of time
        MOV     R2, R4, LSR #24         ; R2 = MSB of time
        SUB     SP, SP, #3*4            ; Create local mouse data buffer
        STMIA   SP, {R0,R1,R2}          ; Write mouse data to buffer

        MOV     R3, #9                  ; Mouse packet size
        MOV     R2, SP                  ; R2-> block to insert
        MOV     R1, #(Buff_Mouse:OR:(1:SHL:31)) ; Block insert to mouse buffer
        Push    "R10,R12"
        MOV     R10, #INSV              ; Insert
        BL      GoVec2                  ; Call the vector in R10
        Pull    "R10,R12"
        ADD     SP, SP, #3*4            ; Destroy mouse data buffer
        Pull    "R0-R5, R12, PC"

; *****************************************************************************
;
;       Read mouse position
;

ReadMouse ROUT
        Push    "R4-R6,R10-R12"
Jeffrey Lee's avatar
Jeffrey Lee committed
113
        LDR     R11, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

        SUB     SP, SP, #3*4            ; Create 9 byte local mouse data buffer
        MOV     R3, #9                  ; Mouse packet size
        MOV     R2, SP                  ; R2-> buffer for data
        MOV     R1, #(Buff_Mouse:OR:(1:SHL:31)) ; Block remove from mouse buffer
        CLRV                            ; Remove not examine
        Push    "R10,R12"
        MOV     R10, #REMV
        BL      GoVec2                  ; Call the vector in R10
        Pull    "R10,R12"

        LDMCCIA SP, {R4,R5,R6}
        ADD     SP, SP, #3*4            ; Destroy mouse data buffer
        BCS     %FT10                   ; Jump if no buffered data

        MOV     R0, R4, LSL #16
        MOV     R0, R0, ASR #16         ; R0 = sign extended x coord
        MOV     R1, R4, ASR #16         ; R1 = sign extended y coord
        AND     R2, R5, #&FF            ; R2 = button state
        MOV     R3, R5, LSR #8          ; R3 = 3 low order bytes of time
        ORR     R3, R3, R6, LSL #24     ; R3 = time

; code inserted here 12-Aug-88 to force position read from buffer to be inside
; CURRENT bounding box; this removes the need to flush buffer when changing
; the bounding box.

        ADR     R4, MouseBounds
        LDMIA   R4, {R4-R6,R10}         ; R4=LCol; R5=BRow; R6=RCol; R10=TRow;
        CMP     R0, R4
        MOVLT   R0, R4
        CMP     R0, R6
        MOVGT   R0, R6
        CMP     R1, R5
        MOVLT   R1, R5
        CMP     R1, R10
        MOVGT   R1, R10

        B       %FT20                   ; correct for origin after clipping

10
        LDRB    R2, MouseButtons

Jeffrey Lee's avatar
Jeffrey Lee committed
156
        LDR     R3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
        LDR     R3, [R3, #MetroGnome]           ; use monotonic variable now

        LDR     R0, MouseX
        LDR     R1, MouseY
20
        VDWS    WsPtr

        LDR     R4, [WsPtr, #OrgX]
        SUB     R0, R0, R4

        LDR     R4, [WsPtr, #OrgY]
        SUB     R1, R1, R4

        Pull    "R4-R6,R10-R12,PC"

172 173
Abso    DCB     "Abso"

Neil Turton's avatar
Neil Turton committed
174 175 176 177 178 179
; *****************************************************************************
;
;       ProcessMouseXY - Called to update mouse position.
;
;       in:     r2  = signed 32-bit X movement
;               r3  = signed 32-bit Y movement
180
;               r4  = "Abso" if absolute movement
Neil Turton's avatar
Neil Turton committed
181 182 183 184 185 186
;               r11 ->KeyWorkSpace
;       out:    r2,r3 corrupted
;
ProcessMouseXY
        Push    "r4,lr"

187 188 189 190 191
; check for absolute position
        LDR     lr, Abso
        TEQ     r4, lr
        BEQ     %FT40

Neil Turton's avatar
Neil Turton committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
; process X movement
        CMP     r2, #0
        BEQ     %FT10

        MOV     r2, r2, LSL #16         ; move delta X to top 16 bits

        LDR     r4, MouseXMult
        MUL     r2, r4, r2

        LDR     r4, MouseX
        ADD     r2, r2, r4, LSL #16     ; add signed value in top 16 bits
        MOV     r2, r2, ASR #16         ; sign extend to 32 bits

        LDR     r4, MouseBoundLCol      ; bound to bounding box
        CMP     r2, r4
        MOVLT   r2, r4
        LDR     r4, MouseBoundRCol
        CMP     r4, r2
        MOVLT   r2, r4
        STR     r2, MouseX

10
; process Y movement
        CMP     r3, #0
        Pull    "r4,pc",EQ

        MOV     r3, r3, LSL #16         ; move delta Y to top 16 bits

        LDR     r4, MouseYMult
        MUL     r3, r4, r3

        LDR     r4, MouseY
        ADD     r3, r3, r4, LSL #16     ; add signed value in top 16 bits
        MOV     r3, r3, ASR #16         ; sign extend to 32 bits

        LDR     r4, MouseBoundBRow      ; bound to bounding box
        CMP     r3, r4
        MOVLT   r3, r4
        LDR     r4, MouseBoundTRow
        CMP     r4, r3
        MOVLT   r3, r4
        STR     r3, MouseY

        Pull    "r4,pc"

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
40
; process absolute position
        MOV     r2, r2, ASL #16         ; look only at bottom 16 bits,
        MOV     r3, r3, ASL #16         ; sign extended
        MOV     r2, r2, ASR #16
        MOV     r3, r3, ASR #16

        LDR     r4, MouseBoundLCol      ; bound to bounding box
        CMP     r2, r4
        MOVLT   r2, r4
        LDR     r4, MouseBoundRCol
        CMP     r4, r2
        MOVLT   r2, r4
        STR     r2, MouseX
        LDR     r4, MouseBoundBRow      ; bound to bounding box
        CMP     r3, r4
        MOVLT   r3, r4
        LDR     r4, MouseBoundTRow
        CMP     r4, r3
        MOVLT   r3, r4
        STR     r3, MouseY
        Pull    "r4,pc"


Neil Turton's avatar
Neil Turton committed
261 262 263 264 265 266 267
; *****************************************************************************
;
;       PollPointer - Called on VSync to get mouse changes.
;
;       out:    corrupts r0-r3,r9-r11
;
PollPointer
268
        Push    "r4,r12,lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
269
        LDR     r11, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
270

271 272 273 274
        LDRB    r0, MouseReporting
        TEQ     r0, #0
        Pull    "r4,r12,pc",NE

Neil Turton's avatar
Neil Turton committed
275 276 277 278
        MOV     r0, #0                  ; Request pointer state.
        LDRB    r1, MouseType
        MOV     r2, #0                  ; Default to no movement.
        MOV     r3, #0
279
        MOV     r4, #0                  ; They might fill this in
Kevin Bracey's avatar
Kevin Bracey committed
280 281
        SavePSR r9                      ; Save current PSR.
        WritePSRc SVC_mode+I_bit, r10   ; Call PointerV in SVC mode, no IRQs.
Neil Turton's avatar
Neil Turton committed
282 283 284 285
        MOV     r10, #PointerV          ; Call PointerV to get movements & button states
        Push    "lr"                    ; Save SVC lr.
        BL      CallVector
        Pull    "lr"                    ; Restore SVC lr.
Kevin Bracey's avatar
Kevin Bracey committed
286 287
        RestPSR r9
        BL      ProcessMouseXY
Neil Turton's avatar
Neil Turton committed
288

289
        Pull    "r4,r12,pc"
Neil Turton's avatar
Neil Turton committed
290

291 292 293 294 295 296 297 298
; *****************************************************************************
;
;       PointerVector - the default PointerV claimant
;
PointerVector
        CMP     r0, #PointerReason_Report
        Pull    pc, NE
        Push    "r2,r3,r11"
Jeffrey Lee's avatar
Jeffrey Lee committed
299
        LDR     r11, =ZeroPage+KeyWorkSpace
300 301 302 303 304 305 306 307
        LDRB    lr, MouseType
        TEQ     r1, lr
        MOVEQ   lr, #1
        STREQB  lr, MouseReporting
        BL      ProcessMouseXY
        Pull    "r2,r3,r11,pc"


Neil Turton's avatar
Neil Turton committed
308 309 310 311 312 313

; *****************************************************************************
;
;       PointerSWI - Handle SWI OS_Pointer calls (read/set pointer type).
;
PointerSWI
Jeffrey Lee's avatar
Jeffrey Lee committed
314
        LDR     r11, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
315 316 317 318 319 320 321 322 323
        TEQ     r0, #0
        LDREQB  r0, MouseType
        BEQ     SLVK

        TEQ     r0, #1
        BNE     %FT10

        Push    "r0,r10,r12,lr"
        STRB    r1, MouseType
324 325
        MOV     r0, #0
        STRB    r0, MouseReporting
Neil Turton's avatar
Neil Turton committed
326 327 328 329 330 331 332 333 334
        MOV     r0, #2
        MOV     r10, #PointerV
        BL      CallVector
        Pull    "r0,r10,r12,lr"
        B       SLVK

10
        ADRL    r0, ErrorBlock_BadParameters
  [ International
335
        Push    "lr"
Neil Turton's avatar
Neil Turton committed
336
        BL      TranslateError
337
        Pull    "lr"
Neil Turton's avatar
Neil Turton committed
338 339 340 341
  ]
        B       SLVK_SetV

        END