2 ; Ullrich von Bassewitz, 2003-12-28
4 ; Common functions of the mouse driver API.
7 .import return0, popsreg, incsp2
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_box: jmp return0
32 mouse_move: jmp return0
33 mouse_buttons: jmp return0
34 mouse_pos: jmp return0
35 mouse_info: jmp return0
36 mouse_ioctl: jmp return0
37 mouse_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
38 mouse_flags: .byte $00
40 ; Driver header signature
42 mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version
46 ;----------------------------------------------------------------------------
47 ; unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c,
49 ; /* Install an already loaded driver. Returns an error code. */
57 ; Check the driver signature
59 ldy #.sizeof(mouse_sig)-1
71 ; Copy the jump vectors
73 ldy #MOUSE_HDR::JUMPTAB
75 @L1: inx ; Skip the JMP opcode
76 jsr copyjv ; Copy one byte
77 jsr copyjv ; Copy one byte
78 cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
81 ; Copy the flags byte. It is located directly behind the jump vectors, so Y
82 ; is already correct when we come here. To save code, we use copyjv - crude
87 ; Copy the callback vectors into the driver space
90 ldy #(MOUSE_HDR::CALLBACKS + .sizeof(MOUSE_HDR::CALLBACKS) - 1)
92 ldy #.sizeof(MOUSE_CALLBACKS)-1
98 dec tmp2 ; Skip opcode byte
102 ; Install the IRQ vector if the driver needs it
104 bit mouse_flags ; Test MOUSE_FLAG_EARLY_IRQ
105 bvc @L3 ; Jump if no interrupts at this time
106 jsr install_irq ; Activate IRQ routine
108 ; Call driver install routine and check for errors
110 @L3: jsr mouse_install
111 tay ; Test error code
112 bne uninstall_irq ; Jump on error
114 ; No errors on INSTALL. If the driver needs late IRQs, enable them now. Be
115 ; careful not to use A/X since these registers contain the error code from
118 bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ
119 bpl Exit ; Jump if vector not needed
121 ldy #$4C ; Jump opcode
122 sty mouse_irq ; Activate IRQ routine
125 ; Uninstall IRQ vector if install routine had errors. A/X may contain the
126 ; error code from mouse_install, so don't use it.
129 ldy #$60 ; RTS opcode
130 sty mouse_irq ; Disable IRQ entry point
133 ; Driver signature invalid. One word is still on the stack
136 lda #MOUSE_ERR_INV_DRIVER
140 ; Copy one byte from the jump vectors
148 ; Copy one byte from the callback vectors
157 ;----------------------------------------------------------------------------
158 ; unsigned char __fastcall__ mouse_uninstall (void);
159 ; /* Uninstall the currently loaded driver. Returns an error code. */
163 ; Depending on the late/early IRQ flag, we will disable IRQs before or after
164 ; calling the driver mouse_uninstall routine.
166 bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ
167 bpl @L1 ; Don't disable interrupts now
168 jsr uninstall_irq ; Disable driver interrupts
169 @L1: jsr mouse_uninstall ; Call driver routine
171 ; We don't check the flag a second time here, since disabling IRQs twice,
172 ; or disabling them if they weren't enabled will do no harm, and the missing
173 ; check will save a few bytes.
175 jsr uninstall_irq ; Disable driver interrupts
177 _mouse_clear_ptr: ; External entry point
180 sta _mouse_drv+1 ; Clear the driver pointer