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
51 .byte MOUSE_FLAG_EARLY_IRQ
53 ; Callback table, set by the kernel before INSTALL is called
54 CHIDE: jmp $0000 ; Hide the cursor
55 CSHOW: jmp $0000 ; Show the cursor
56 CMOVEX: jmp $0000 ; Move the cursor to X coord
57 CMOVEY: jmp $0000 ; Move the cursor to Y coord
59 ; ------------------------------------------------------------------------
67 ; ------------------------------------------------------------------------
71 offsets:.byte $05 ; Pascal 1.0 ID byte
72 .byte $07 ; Pascal 1.0 ID byte
73 .byte $0B ; Pascal 1.1 generic signature byte
74 .byte $0C ; Device signature byte
76 values: .byte $38 ; Fixed
79 .byte $20 ; X-Y pointing device type 0
83 ; ------------------------------------------------------------------------
88 ; Lookup and patch firmware address lobyte
89 lookup: ldy $FF00,x ; Patched at runtime
90 sty jump+1 ; Modify code below
92 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
93 ; "Enter all mouse routines (...) with the X register set to $Cn
94 ; and Y register set to $n0, where n = the slot number."
95 xparam: ldx #$FF ; Patched at runtime
96 yparam: ldy #$FF ; Patched at runtime
98 jump: jmp $FFFF ; Patched at runtime
100 ; ------------------------------------------------------------------------
104 ; INSTALL: Is called after the driver is loaded into memory. If possible,
105 ; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X.
112 ; Search for AppleMouse II firmware in slots 1 - 7
118 ; Mouse firmware not found
119 lda #<MOUSE_ERR_NO_DEVICE
120 ldx #>MOUSE_ERR_NO_DEVICE
123 ; Check Pascal 1.1 Firmware Protocol ID bytes
132 ; Get and patch firmware address hibyte
138 ; Convert to and save slot number
143 ; Convert to and patch I/O register index
150 ; The AppleMouse II Card needs the ROM switched in
151 ; to be able to detect an Apple //e and use RDVBL
154 ; Reset mouse hardware
158 ; Switch in LC bank 2 for R/O
166 ; Set initial mouse clamps
171 lda #$00 ; Set x clamps
180 lda #$01 ; Set y clamps
184 ; Set initial mouse position
200 ; Turn VBL interrupt on
205 ; Enable interrupts and return success
211 ; UNINSTALL: Is called before the driver is removed from memory.
212 ; No return code required (the driver is removed from memory on return).
221 bne common ; Branch always
223 ; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a
224 ; counter for calls to show/hide, and the driver entry point is only called
225 ; if the mouse is currently visible and should get hidden. For most drivers,
226 ; no special action is required besides hiding the mouse cursor.
227 ; No return code required.
235 ; SHOW: Is called to show the mouse cursor. The mouse kernel manages a
236 ; counter for calls to show/hide, and the driver entry point is only called
237 ; if the mouse is currently hidden and should become visible. For most drivers,
238 ; no special action is required besides enabling the mouse cursor.
239 ; No return code required.
244 ; BOX: Set the mouse bounding box. The parameters are passed as they come from
245 ; the C program, that is, maxy in A/X and the other parameters on the stack.
246 ; The C wrapper will remove the parameters from the stack when the driver
248 ; No checks are done if the mouse is currently inside the box, this is the job
249 ; of the caller. It is not necessary to validate the parameters, trust the
250 ; caller and save some code here. No return code required.
252 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
253 ; "Disable interrupts before placing position information in the screen holes."
260 ldx #$01 ; Set y clamps
261 ldy #$00 ; Start at top of stack
264 ldx #$00 ; Set x clamps
265 ldy #$00 ; Start at top of stack
289 bne common ; Branch always
291 ; MOVE: Move the mouse to a new position. The position is passed as it comes
292 ; from the C program, that is: x on the stack and y in A/X. The C wrapper will
293 ; remove the parameter from the stack on return.
294 ; No checks are done if the new position is valid (within the bounding box or
295 ; the screen). No return code required.
307 ldy #$00 ; Start at top of stack
320 bne common ; Branch always
322 ; BUTTONS: Return the button mask in A/X.
324 lda info + MOUSE_INFO::BUTTONS
328 ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
329 ; No return code required.
331 ldx #.sizeof(MOUSE_POS)-1
332 bne copy ; Branch always
334 ; INFO: Returns mouse position and current button mask in the MOUSE_INFO
335 ; struct pointed to by ptr1. No return code required.
337 ldx #.sizeof(MOUSE_INFO)-1
349 ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
350 ; specific data in ptr1, and the ioctl code in A.
351 ; Must return an MOUSE_ERR_xx code in A/X.
353 lda #<MOUSE_ERR_INV_IOCTL
354 ldx #>MOUSE_ERR_INV_IOCTL
357 ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
358 ; registers are already saved, no parameters are passed, but the carry flag
359 ; is clear on entry. The routine must return with carry set if the interrupt
360 ; was handled, otherwise with carry clear.
362 ; Check for installed mouse
366 ; Check for mouse interrupt
370 clc ; Interrupt not handled
381 ; Extract button down values
382 asl ; C = Button 0 is currently down
383 and #%00100000 ; !Z = Button 1 is currently down
390 : sta info + MOUSE_INFO::BUTTONS
392 ; Check for mouse movement
394 and #%00100000 ; X or Y changed since last READMOUSE
397 ; Remove the cursor at the old position
400 ; Get and set the new X position
404 sta info + MOUSE_POS::XCOORD
405 stx info + MOUSE_POS::XCOORD+1
408 ; Get and set the new Y position
412 sta info + MOUSE_POS::YCOORD
413 stx info + MOUSE_POS::YCOORD+1
416 ; Check for visibility
420 ; Draw the cursor at the new position
422 : sec ; Interrupt handled