2 ; Driver for the AppleMouse II Card.
4 ; Oliver Schmidt, 03.09.2005
7 .include "zeropage.inc"
8 .include "mouse-kernel.inc"
11 ; ------------------------------------------------------------------------
13 SETMOUSE = $12 ; Sets mouse mode
14 SERVEMOUSE = $13 ; Services mouse interrupt
15 READMOUSE = $14 ; Reads mouse position
16 CLEARMOUSE = $15 ; Clears mouse position to 0 (for delta mode)
17 POSMOUSE = $16 ; Sets mouse position to a user-defined pos
18 CLAMPMOUSE = $17 ; Sets mouse bounds in a window
19 HOMEMOUSE = $18 ; Sets mouse to upper-left corner of clamp win
20 INITMOUSE = $19 ; Resets mouse clamps to default values and
21 ; sets mouse position to 0,0
29 ; ------------------------------------------------------------------------
34 .byte $6D, $6F, $75 ; "mou"
35 .byte MOUSE_API_VERSION ; Mouse driver API version number
52 .byte MOUSE_FLAG_EARLY_IRQ
54 ; Callback table, set by the kernel before INSTALL is called
55 CHIDE: jmp $0000 ; Hide the cursor
56 CSHOW: jmp $0000 ; Show the cursor
57 CMOVEX: jmp $0000 ; Move the cursor to X coord
58 CMOVEY: jmp $0000 ; Move the cursor to Y coord
60 ; ------------------------------------------------------------------------
69 ; ------------------------------------------------------------------------
73 offsets:.byte $05 ; Pascal 1.0 ID byte
74 .byte $07 ; Pascal 1.0 ID byte
75 .byte $0B ; Pascal 1.1 generic signature byte
76 .byte $0C ; Device signature byte
78 values: .byte $38 ; Fixed
81 .byte $20 ; X-Y pointing device type 0
85 inibox: .word 0 ; MinX
90 ; ------------------------------------------------------------------------
95 ; Lookup and patch firmware address lobyte
96 lookup: ldy $FF00,x ; Patched at runtime
97 sty jump+1 ; Modify code below
99 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
100 ; "Enter all mouse routines (...) with the X register set to $Cn
101 ; and Y register set to $n0, where n = the slot number."
102 xparam: ldx #$FF ; Patched at runtime
103 yparam: ldy #$FF ; Patched at runtime
105 jump: jmp $FFFF ; Patched at runtime
107 ; ------------------------------------------------------------------------
111 ; INSTALL: Is called after the driver is loaded into memory. If possible,
112 ; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X.
119 ; Search for AppleMouse II firmware in slots 1 - 7
125 ; Mouse firmware not found
126 lda #<MOUSE_ERR_NO_DEVICE
127 ldx #>MOUSE_ERR_NO_DEVICE
130 ; Check Pascal 1.1 Firmware Protocol ID bytes
139 ; Get and patch firmware address hibyte
145 ; Disable interrupts now because setting the slot number makes
146 ; the IRQ handler (maybe called due to some non-mouse IRQ) try
147 ; calling the firmware which isn't correctly set up yet
150 ; Convert to and save slot number
154 ; Convert to and patch I/O register index
161 ; The AppleMouse II Card needs the ROM switched in
162 ; to be able to detect an Apple //e and use RDVBL
165 ; Reset mouse hardware
169 ; Switch in LC bank 2 for R/O
177 ; Set initial mouse clamps
182 ; Set initial mouse position
198 ; Turn VBL interrupt on
203 ; Enable interrupts and return success
209 ; UNINSTALL: Is called before the driver is removed from memory.
210 ; No return code required (the driver is removed from memory on return).
219 bne common ; Branch always
221 ; SETBOX: Set the mouse bounding box. The parameters are passed as they come
222 ; from the C program, that is, a pointer to a mouse_box struct in A/X.
223 ; No checks are done if the mouse is currently inside the box, this is the job
224 ; of the caller. It is not necessary to validate the parameters, trust the
225 ; caller and save some code here. No return code required.
239 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
240 ; "Disable interrupts before placing position information in the
269 bne common ; Branch always
271 ; GETBOX: Return the mouse bounding box. The parameters are passed as they
272 ; come from the C program, that is, a pointer to a mouse_box struct in A/X.
277 ldy #.sizeof(MOUSE_BOX)-1
284 ; MOVE: Move the mouse to a new position. The position is passed as it comes
285 ; from the C program, that is: x on the stack and y in A/X. The C wrapper will
286 ; remove the parameter from the stack on return.
287 ; No checks are done if the new position is valid (within the bounding box or
288 ; the screen). No return code required.
300 ldy #$00 ; Start at top of stack
313 bne common ; Branch always
315 ; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a
316 ; counter for calls to show/hide, and the driver entry point is only called
317 ; if the mouse is currently visible and should get hidden. For most drivers,
318 ; no special action is required besides hiding the mouse cursor.
319 ; No return code required.
327 ; SHOW: Is called to show the mouse cursor. The mouse kernel manages a
328 ; counter for calls to show/hide, and the driver entry point is only called
329 ; if the mouse is currently hidden and should become visible. For most drivers,
330 ; no special action is required besides enabling the mouse cursor.
331 ; No return code required.
336 ; BUTTONS: Return the button mask in A/X.
338 lda info + MOUSE_INFO::BUTTONS
342 ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
343 ; No return code required.
345 ldy #.sizeof(MOUSE_POS)-1
346 bne copy ; Branch always
348 ; INFO: Returns mouse position and current button mask in the MOUSE_INFO
349 ; struct pointed to by ptr1. No return code required.
351 ldy #.sizeof(MOUSE_INFO)-1
360 ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
361 ; specific data in ptr1, and the ioctl code in A.
362 ; Must return an MOUSE_ERR_xx code in A/X.
364 lda #<MOUSE_ERR_INV_IOCTL
365 ldx #>MOUSE_ERR_INV_IOCTL
368 ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
369 ; registers are already saved, no parameters are passed, but the carry flag
370 ; is clear on entry. The routine must return with carry set if the interrupt
371 ; was handled, otherwise with carry clear.
373 ; Check for installed mouse
377 ; Check for mouse interrupt
381 clc ; Interrupt not handled
392 ; Extract button down values
393 asl ; C = Button 0 is currently down
394 and #%00100000 ; !Z = Button 1 is currently down
401 : sta info + MOUSE_INFO::BUTTONS
403 ; Check for mouse movement
405 and #%00100000 ; X or Y changed since last READMOUSE
408 ; Remove the cursor at the old position
411 ; Get and set the new X position
415 sta info + MOUSE_POS::XCOORD
416 stx info + MOUSE_POS::XCOORD+1
419 ; Get and set the new Y position
423 sta info + MOUSE_POS::YCOORD
424 stx info + MOUSE_POS::YCOORD+1
427 ; Check for visibility
431 ; Draw the cursor at the new position
433 : sec ; Interrupt handled