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
55 .byte MOUSE_FLAG_EARLY_IRQ
57 ; Callback table, set by the kernel before INSTALL is called
58 CHIDE: jmp $0000 ; Hide the cursor
59 CSHOW: jmp $0000 ; Show the cursor
60 CMOVEX: jmp $0000 ; Move the cursor to X coord
61 CMOVEY: jmp $0000 ; Move the cursor to Y coord
63 ; ------------------------------------------------------------------------
72 ; ------------------------------------------------------------------------
76 offsets:.byte $05 ; Pascal 1.0 ID byte
77 .byte $07 ; Pascal 1.0 ID byte
78 .byte $0B ; Pascal 1.1 generic signature byte
79 .byte $0C ; Device signature byte
81 values: .byte $38 ; Fixed
84 .byte $20 ; X-Y pointing device type 0
88 inibox: .word 0 ; MinX
93 ; ------------------------------------------------------------------------
98 ; Lookup and patch firmware address lobyte
99 lookup: ldy $FF00,x ; Patched at runtime
100 sty jump+1 ; Modify code below
102 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
103 ; "Enter all mouse routines (...) with the X register set to $Cn
104 ; and Y register set to $n0, where n = the slot number."
105 xparam: ldx #$FF ; Patched at runtime
106 yparam: ldy #$FF ; Patched at runtime
108 jump: jmp $FFFF ; Patched at runtime
110 ; ------------------------------------------------------------------------
114 ; INSTALL: Is called after the driver is loaded into memory. If possible,
115 ; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X.
122 ; Search for AppleMouse II firmware in slots 1 - 7
128 ; Mouse firmware not found
129 lda #<MOUSE_ERR_NO_DEVICE
130 ldx #>MOUSE_ERR_NO_DEVICE
133 ; Check Pascal 1.1 Firmware Protocol ID bytes
142 ; Get and patch firmware address hibyte
148 ; Disable interrupts now because setting the slot number makes
149 ; the IRQ handler (maybe called due to some non-mouse IRQ) try
150 ; calling the firmware which isn't correctly set up yet
153 ; Convert to and save slot number
157 ; Convert to and patch I/O register index
164 ; The AppleMouse II Card needs the ROM switched in
165 ; to be able to detect an Apple //e and use RDVBL
168 ; Reset mouse hardware
172 ; Switch in LC bank 2 for R/O
180 ; Set initial mouse clamps
185 ; Set initial mouse position
201 ; Turn VBL interrupt on
206 ; Enable interrupts and return success
212 ; UNINSTALL: Is called before the driver is removed from memory.
213 ; No return code required (the driver is removed from memory on return).
222 bne common ; Branch always
224 ; SETBOX: Set the mouse bounding box. The parameters are passed as they come
225 ; from the C program, that is, a pointer to a mouse_box struct in A/X.
226 ; No checks are done if the mouse is currently inside the box, this is the job
227 ; of the caller. It is not necessary to validate the parameters, trust the
228 ; caller and save some code here. No return code required.
242 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
243 ; "Disable interrupts before placing position information in the
272 bne common ; Branch always
274 ; GETBOX: Return the mouse bounding box. The parameters are passed as they
275 ; come from the C program, that is, a pointer to a mouse_box struct in A/X.
280 ldy #.sizeof(MOUSE_BOX)-1
287 ; MOVE: Move the mouse to a new position. The position is passed as it comes
288 ; from the C program, that is: x on the stack and y in A/X. The C wrapper will
289 ; remove the parameter from the stack on return.
290 ; No checks are done if the new position is valid (within the bounding box or
291 ; the screen). No return code required.
303 ldy #$00 ; Start at top of stack
316 bne common ; Branch always
318 ; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a
319 ; counter for calls to show/hide, and the driver entry point is only called
320 ; if the mouse is currently visible and should get hidden. For most drivers,
321 ; no special action is required besides hiding the mouse cursor.
322 ; No return code required.
330 ; SHOW: Is called to show the mouse cursor. The mouse kernel manages a
331 ; counter for calls to show/hide, and the driver entry point is only called
332 ; if the mouse is currently hidden and should become visible. For most drivers,
333 ; no special action is required besides enabling the mouse cursor.
334 ; No return code required.
339 ; BUTTONS: Return the button mask in A/X.
341 lda info + MOUSE_INFO::BUTTONS
345 ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
346 ; No return code required.
348 ldy #.sizeof(MOUSE_POS)-1
349 bne copy ; Branch always
351 ; INFO: Returns mouse position and current button mask in the MOUSE_INFO
352 ; struct pointed to by ptr1. No return code required.
354 ldy #.sizeof(MOUSE_INFO)-1
363 ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
364 ; specific data in ptr1, and the ioctl code in A.
365 ; Must return an MOUSE_ERR_xx code in A/X.
367 lda #<MOUSE_ERR_INV_IOCTL
368 ldx #>MOUSE_ERR_INV_IOCTL
371 ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
372 ; registers are already saved, no parameters are passed, but the carry flag
373 ; is clear on entry. The routine must return with carry set if the interrupt
374 ; was handled, otherwise with carry clear.
376 ; Check for installed mouse
380 ; Check for mouse interrupt
384 clc ; Interrupt not handled
395 ; Extract button down values
396 asl ; C = Button 0 is currently down
397 and #%00100000 ; !Z = Button 1 is currently down
404 : sta info + MOUSE_INFO::BUTTONS
406 ; Check for mouse movement
408 and #%00100000 ; X or Y changed since last READMOUSE
411 ; Remove the cursor at the old position
414 ; Get and set the new X position
418 sta info + MOUSE_POS::XCOORD
419 stx info + MOUSE_POS::XCOORD+1
422 ; Get and set the new Y position
426 sta info + MOUSE_POS::YCOORD
427 stx info + MOUSE_POS::YCOORD+1
430 ; Check for visibility
434 ; Draw the cursor at the new position
436 : sec ; Interrupt handled