2 ; Ullrich von Bassewitz, 2003-12-28, 2009-09-26
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_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
72 ; Copy the jump vectors
74 ldy #MOUSE_HDR::JUMPTAB
76 @L1: inx ; Skip the JMP opcode
77 jsr copyjv ; Copy one byte
78 jsr copyjv ; Copy one byte
79 cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
82 ; Copy the flags byte. It is located directly behind the jump vectors, so Y
83 ; is already correct when we come here. To save code, we use copyjv - crude
88 ; Copy the callback vectors into the driver space
91 ldy #(MOUSE_HDR::CALLBACKS + .sizeof(MOUSE_HDR::CALLBACKS) - 1)
93 ldy #.sizeof(MOUSE_CALLBACKS)-1
99 dec tmp2 ; Skip opcode byte
103 ; Install the IRQ vector if the driver needs it
105 bit mouse_flags ; Test MOUSE_FLAG_EARLY_IRQ
106 bvc @L3 ; Jump if no interrupts at this time
107 jsr install_irq ; Activate IRQ routine
109 ; Call driver install routine and check for errors
111 @L3: jsr mouse_install
112 tay ; Test error code
113 bne uninstall_irq ; Jump on error
115 ; No errors on INSTALL. If the driver needs late IRQs, enable them now. Be
116 ; careful not to use A/X since these registers contain the error code from
119 bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ
120 bpl Exit ; Jump if vector not needed
122 ldy #$4C ; Jump opcode
123 sty mouse_irq ; Activate IRQ routine
126 ; Uninstall IRQ vector if install routine had errors. A/X may contain the
127 ; error code from mouse_install, so don't use it.
130 ldy #$60 ; RTS opcode
131 sty mouse_irq ; Disable IRQ entry point
134 ; Driver signature invalid. One word is still on the stack
137 lda #MOUSE_ERR_INV_DRIVER
141 ; Copy one byte from the jump vectors
149 ; Copy one byte from the callback vectors
158 ;----------------------------------------------------------------------------
159 ; unsigned char __fastcall__ mouse_uninstall (void);
160 ; /* Uninstall the currently loaded driver. Returns an error code. */
164 ; Depending on the late/early IRQ flag, we will disable IRQs before or after
165 ; calling the driver mouse_uninstall routine.
167 bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ
168 bpl @L1 ; Don't disable interrupts now
169 jsr uninstall_irq ; Disable driver interrupts
170 @L1: jsr mouse_uninstall ; Call driver routine
172 ; We don't check the flag a second time here, since disabling IRQs twice,
173 ; or disabling them if they weren't enabled will do no harm, and the missing
174 ; check will save a few bytes.
176 jsr uninstall_irq ; Disable driver interrupts
178 _mouse_clear_ptr: ; External entry point
181 sta _mouse_drv+1 ; Clear the driver pointer