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 CPREP: jmp $0000 ; Prepare to move the cursor
61 CDRAW: jmp $0000 ; Draw the cursor
62 CMOVEX: jmp $0000 ; Move the cursor to X coord
63 CMOVEY: jmp $0000 ; Move the cursor to Y coord
65 ; ------------------------------------------------------------------------
73 ; ------------------------------------------------------------------------
77 offsets:.byte $05 ; Pascal 1.0 ID byte
78 .byte $07 ; Pascal 1.0 ID byte
79 .byte $0B ; Pascal 1.1 generic signature byte
80 .byte $0C ; Device signature byte
82 values: .byte $38 ; Fixed
85 .byte $20 ; X-Y pointing device type 0
89 inibox: .word 0 ; MinX
94 ; ------------------------------------------------------------------------
99 ; Lookup and patch firmware address lobyte
100 lookup: ldy $FF00,x ; Patched at runtime
101 sty jump+1 ; Modify code below
103 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
104 ; "Enter all mouse routines (...) with the X register set to $Cn
105 ; and Y register set to $n0, where n = the slot number."
106 xparam: ldx #$FF ; Patched at runtime
107 yparam: ldy #$FF ; Patched at runtime
109 jump: jmp $FFFF ; Patched at runtime
111 ; ------------------------------------------------------------------------
115 ; INSTALL: Is called after the driver is loaded into memory. If possible,
116 ; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X.
123 ; Search for AppleMouse II firmware in slots 1 - 7
129 ; Mouse firmware not found
130 lda #<MOUSE_ERR_NO_DEVICE
131 ldx #>MOUSE_ERR_NO_DEVICE
134 ; Check Pascal 1.1 Firmware Protocol ID bytes
143 ; Get and patch firmware address hibyte
149 ; Disable interrupts now because setting the slot number makes
150 ; the IRQ handler (maybe called due to some non-mouse IRQ) try
151 ; calling the firmware which isn't correctly set up yet
154 ; Convert to and save slot number
158 ; Convert to and patch I/O register index
165 ; The AppleMouse II Card needs the ROM switched in
166 ; to be able to detect an Apple //e and use RDVBL
169 ; Reset mouse hardware
173 ; Switch in LC bank 2 for R/O
181 ; Set initial mouse clamps
186 ; Set initial mouse position
202 ; Turn VBL interrupt on
207 ; Enable interrupts and return success
213 ; UNINSTALL: Is called before the driver is removed from memory.
214 ; No return code required (the driver is removed from memory on return).
223 bne common ; Branch always
225 ; SETBOX: Set the mouse bounding box. The parameters are passed as they come
226 ; from the C program, that is, a pointer to a mouse_box struct in A/X.
227 ; No checks are done if the mouse is currently inside the box, this is the job
228 ; of the caller. It is not necessary to validate the parameters, trust the
229 ; caller and save some code here. No return code required.
243 ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
244 ; "Disable interrupts before placing position information in the
273 bne common ; Branch always
275 ; GETBOX: Return the mouse bounding box. The parameters are passed as they
276 ; come from the C program, that is, a pointer to a mouse_box struct in A/X.
281 ldy #.sizeof(MOUSE_BOX)-1
288 ; MOVE: Move the mouse to a new position. The position is passed as it comes
289 ; from the C program, that is: x on the stack and y in A/X. The C wrapper will
290 ; remove the parameter from the stack on return.
291 ; No checks are done if the new position is valid (within the bounding box or
292 ; the screen). No return code required.
304 ldy #$00 ; Start at top of stack
317 bne common ; Branch always
319 ; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a
320 ; counter for calls to show/hide, and the driver entry point is only called
321 ; if the mouse is currently visible and should get hidden. For most drivers,
322 ; no special action is required besides hiding the mouse cursor.
323 ; 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.
341 ; BUTTONS: Return the button mask in A/X.
343 lda info + MOUSE_INFO::BUTTONS
347 ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
348 ; No return code required.
350 ldy #.sizeof(MOUSE_POS)-1
351 bne copy ; Branch always
353 ; INFO: Returns mouse position and current button mask in the MOUSE_INFO
354 ; struct pointed to by ptr1. No return code required.
356 ldy #.sizeof(MOUSE_INFO)-1
365 ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
366 ; specific data in ptr1, and the ioctl code in A.
367 ; Must return an MOUSE_ERR_xx code in A/X.
369 lda #<MOUSE_ERR_INV_IOCTL
370 ldx #>MOUSE_ERR_INV_IOCTL
373 ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
374 ; registers are already saved, no parameters are passed, but the carry flag
375 ; is clear on entry. The routine must return with carry set if the interrupt
376 ; was handled, otherwise with carry clear.
378 ; Check for installed mouse
382 ; Check for mouse interrupt
386 clc ; Interrupt not handled
397 ; Extract button down values
398 asl ; C = Button 0 is currently down
399 and #%00100000 ; !Z = Button 1 is currently down
406 : sta info + MOUSE_INFO::BUTTONS
408 ; Check for mouse movement
410 and #%00100000 ; X or Y changed since last READMOUSE
413 ; Remove the cursor at the old position
416 ; Get and set the new X position
420 sta info + MOUSE_POS::XCOORD
421 stx info + MOUSE_POS::XCOORD+1
424 ; Get and set the new Y position
428 sta info + MOUSE_POS::YCOORD
429 stx info + MOUSE_POS::YCOORD+1
432 ; Draw the cursor at the new position
434 sec ; Interrupt handled