2 ; Ullrich von Bassewitz, 2003-12-28, 2009-09-26
4 ; Common functions of the mouse driver API.
7 .import return0, popsreg, incsp2, mouse_libref
8 .importzp sreg, ptr1, tmp1, tmp2
9 .interruptor mouse_irq ; Export as IRQ handler
11 .include "mouse-kernel.inc"
15 ;----------------------------------------------------------------------------
20 _mouse_drv: .res 2 ; Pointer to driver
22 _mouse_hidden: .res 1 ; Mouse visibility flag
24 ; Jump table for the driver functions.
27 mouse_install: jmp return0
28 mouse_uninstall:jmp return0
29 mouse_hide: jmp return0
30 mouse_show: jmp return0
31 mouse_setbox: jmp return0
32 mouse_getbox: jmp return0
33 mouse_move: jmp return0
34 mouse_buttons: jmp return0
35 mouse_pos: jmp return0
36 mouse_info: jmp return0
37 mouse_ioctl: jmp return0
38 mouse_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
39 mouse_flags: .byte $00
41 ; Driver header signature
43 mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version
47 ;----------------------------------------------------------------------------
48 ; unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c,
50 ; /* Install an already loaded driver. Returns an error code. */
58 ; Check the driver signature
60 ldy #.sizeof(mouse_sig)-1
67 ; Set the library reference
69 ldy #MOUSE_HDR::LIBREF
81 ; Copy the jump vectors
83 ldy #MOUSE_HDR::JUMPTAB
85 @L1: inx ; Skip the JMP opcode
86 jsr copyjv ; Copy one byte
87 jsr copyjv ; Copy one byte
88 cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
91 ; Copy the flags byte. It is located directly behind the jump vectors, so Y
92 ; is already correct when we come here. To save code, we use copyjv - crude
97 ; Copy the callback vectors into the driver space
100 ldy #(MOUSE_HDR::CALLBACKS + .sizeof(MOUSE_HDR::CALLBACKS) - 1)
102 ldy #.sizeof(MOUSE_CALLBACKS)-1
108 dec tmp2 ; Skip opcode byte
112 ; Install the IRQ vector if the driver needs it
114 bit mouse_flags ; Test MOUSE_FLAG_EARLY_IRQ
115 bvc @L3 ; Jump if no interrupts at this time
116 jsr install_irq ; Activate IRQ routine
118 ; Call driver install routine and check for errors
120 @L3: jsr mouse_install
121 tay ; Test error code
122 bne uninstall_irq ; Jump on error
124 ; No errors on INSTALL. If the driver needs late IRQs, enable them now. Be
125 ; careful not to use A/X since these registers contain the error code from
128 bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ
129 bpl Exit ; Jump if vector not needed
131 ldy #$4C ; Jump opcode
132 sty mouse_irq ; Activate IRQ routine
135 ; Uninstall IRQ vector if install routine had errors. A/X may contain the
136 ; error code from mouse_install, so don't use it.
139 ldy #$60 ; RTS opcode
140 sty mouse_irq ; Disable IRQ entry point
143 ; Driver signature invalid. One word is still on the stack
146 lda #MOUSE_ERR_INV_DRIVER
150 ; Copy one byte from the jump vectors
158 ; Copy one byte from the callback vectors
167 ;----------------------------------------------------------------------------
168 ; unsigned char mouse_uninstall (void);
169 ; /* Uninstall the currently loaded driver. Returns an error code. */
173 ; Depending on the late/early IRQ flag, we will disable IRQs before or after
174 ; calling the driver mouse_uninstall routine.
176 bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ
177 bpl @L1 ; Don't disable interrupts now
178 jsr uninstall_irq ; Disable driver interrupts
179 @L1: jsr mouse_uninstall ; Call driver routine
181 ; We don't check the flag a second time here, since disabling IRQs twice,
182 ; or disabling them if they weren't enabled will do no harm, and the missing
183 ; check will save a few bytes.
185 jsr uninstall_irq ; Disable driver interrupts
187 _mouse_clear_ptr: ; External entry point
190 sta _mouse_drv+1 ; Clear the driver pointer