2 ; Mouse driver for ST & Amiga mouses and Atari trakball.
4 ; Original access routines: 05/07/2000 Freddy Offenga
5 ; Converted to driver: Christian Groessler, 2014-01-04
8 ; AMIGA_MOUSE - builds Amiga mouse version
9 ; TRAK_MOUSE - builds trakball version
10 ; If none of these defines are active, the ST mouse version
14 .include "zeropage.inc"
15 .include "mouse-kernel.inc"
20 .if .not ( .defined (AMIGA_MOUSE) .or .defined (TRAK_MOUSE))
24 ; ------------------------------------------------------------------------
25 ; Header. Includes jump table
33 .byte $6d, $6f, $75 ; "mou"
34 .byte MOUSE_API_VERSION ; Mouse driver API version number
57 .byte MOUSE_FLAG_LATE_IRQ
59 ; Callback table, set by the kernel before INSTALL is called
61 CHIDE: jmp $0000 ; Hide the cursor
62 CSHOW: jmp $0000 ; Show the cursor
63 CMOVEX: jmp $0000 ; Move the cursor to X coord
64 CMOVEY: jmp $0000 ; Move the cursor to Y coord
67 ;----------------------------------------------------------------------------
80 ;----------------------------------------------------------------------------
81 ; Global variables. The bounding box values are sorted so that they can be
82 ; written with the least effort in the SETBOX and GETBOX routines, so don't
88 YPos: .res 2 ; Current mouse position, Y
89 XPos: .res 2 ; Current mouse position, X
90 XMin: .res 2 ; X1 value of bounding box
91 YMin: .res 2 ; Y1 value of bounding box
92 XMax: .res 2 ; X2 value of bounding box
93 YMax: .res 2 ; Y2 value of bounding box
94 Buttons: .res 1 ; Button mask
102 .if .defined (AMIGA_MOUSE) .or .defined (ST_MOUSE)
112 ; Default values for some of the above variables
116 ; (We use ".proc" because we want to define both a label and a scope.)
119 .word (SCREEN_HEIGHT+1)/2 ; YPos
120 .word (SCREEN_WIDTH+1)/2 ; XPos
123 .word SCREEN_WIDTH ; XMax
124 .word SCREEN_HEIGHT ; YMax
130 ; ST mouse lookup table
132 STTab: .byte $FF,$01,$00,$01
133 .byte $00,$FF,$00,$01
134 .byte $01,$00,$FF,$00
135 .byte $01,$00,$01,$FF
141 ; Amiga mouse lookup table
143 AmiTab: .byte $FF,$01,$00,$FF
144 .byte $00,$FF,$FF,$01
145 .byte $01,$FF,$FF,$00
146 .byte $FF,$00,$01,$FF
152 ;----------------------------------------------------------------------------
153 ; INSTALL routine. Is called after the driver is loaded into memory. If
154 ; possible, check if the hardware is present.
155 ; Must return an MOUSE_ERR_xx code in a/x.
159 ; Initialize variables. Just copy the default stuff over
161 ldx #.sizeof(DefVars)-1
167 ; Be sure the mouse cursor is invisible and at the default location. We
168 ; need to do that here, because our mouse interrupt handler doesn't set the
169 ; mouse position if it hasn't changed.
185 ; install timer irq routine to poll mouse
211 ora #%00000001 ; timer 1 enable
215 ; Done, return zero (= MOUSE_ERR_OK)
221 ;----------------------------------------------------------------------------
222 ; UNINSTALL routine. Is called before the driver is removed from memory.
223 ; No return code required (the driver is removed from memory on return).
227 ; uninstall timer irq routine
230 and #%11111110 ; timer 1 disable
244 ;----------------------------------------------------------------------------
245 ; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
246 ; a counter for calls to show/hide, and the driver entry point is only called
247 ; if the mouse is currently visible and should get hidden. For most drivers,
248 ; no special action is required besides hiding the mouse cursor.
249 ; No return code required.
258 ;----------------------------------------------------------------------------
259 ; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
260 ; a counter for calls to show/hide, and the driver entry point is only called
261 ; if the mouse is currently hidden and should become visible. For most drivers,
262 ; no special action is required besides enabling the mouse cursor.
263 ; No return code required.
272 ;----------------------------------------------------------------------------
273 ; SETBOX: Set the mouse bounding box. The parameters are passed as they come
274 ; from the C program, that is, a pointer to a mouse_box struct in a/x.
275 ; No checks are done if the mouse is currently inside the box, this is the job
276 ; of the caller. It is not necessary to validate the parameters, trust the
277 ; caller and save some code here. No return code required.
280 stx ptr1+1 ; Save data pointer
282 ldy #.sizeof (MOUSE_BOX)-1
294 ;----------------------------------------------------------------------------
295 ; GETBOX: Return the mouse bounding box. The parameters are passed as they
296 ; come from the C program, that is, a pointer to a mouse_box struct in a/x.
299 stx ptr1+1 ; Save data pointer
301 ldy #.sizeof (MOUSE_BOX)-1
313 ;----------------------------------------------------------------------------
314 ; MOVE: Move the mouse to a new position. The position is passed as it comes
315 ; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
316 ; remove the parameter from the stack on return.
317 ; No checks are done if the new position is valid (within the bounding box or
318 ; the screen). No return code required.
339 stx YPos+1 ; New Y position
350 sta XPos ; New X position
353 jsr CMOVEX ; Move the cursor
360 @Ret: plp ; Restore interrupt flag
363 ;----------------------------------------------------------------------------
364 ; BUTTONS: Return the button mask in a/x.
371 ;----------------------------------------------------------------------------
372 ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
373 ; No return code required.
375 POS: ldy #MOUSE_POS::XCOORD ; Structure offset
378 sei ; Disable interrupts
379 lda XPos ; Transfer the position
388 plp ; Restore interrupt flag
391 sta (ptr1),y ; Store last byte
395 ;----------------------------------------------------------------------------
396 ; INFO: Returns mouse position and current button mask in the MOUSE_INFO
397 ; struct pointed to by ptr1. No return code required.
399 ; We're cheating here to keep the code smaller: The first fields of the
400 ; mouse_info struct are identical to the mouse_pos struct, so we will just
401 ; call _mouse_pos to initialize the struct pointer and fill the position
406 ; Fill in the button state
409 ldy #MOUSE_INFO::BUTTONS
414 ;----------------------------------------------------------------------------
415 ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
416 ; specific data in ptr1, and the ioctl code in A.
417 ; Must return an error code in a/x.
420 IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioclts for now
421 ldx #>MOUSE_ERR_INV_IOCTL
424 ;----------------------------------------------------------------------------
425 ; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
426 ; (so be careful). The routine MUST return carry set if the interrupt has been
427 ; 'handled' - which means that the interrupt source is gone. Otherwise it
428 ; MUST return carry clear.
433 ; Check for a pressed button and place the result into Buttons
436 lda TRIG0 ; joystick #0 trigger
437 bne @L0 ; not pressed
441 ; Update coordinates if needed
460 ; Limit the X coordinate to the bounding box
484 ; Limit the Y coordinate to the bounding box
516 ;----------------------------------------------------------------------------
517 ; T1Han: Local IRQ routine to poll mouse
589 .elseif .defined (AMIGA_MOUSE)
591 ; Amiga mouse version
644 .elseif .defined (TRAK_MOUSE)