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 .condes mouse_irq, 2 ; 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
39 ; Driver header signature
41 mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version
44 ;----------------------------------------------------------------------------
45 ; unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c,
47 ; /* Install an already loaded driver. Returns an error code. */
55 ; Check the driver signature
57 ldy #.sizeof(mouse_sig)-1
69 ; Copy the jump vectors
71 ldy #MOUSE_HDR::JUMPTAB
73 @L1: inx ; Skip the JMP opcode
74 jsr copyjv ; Copy one byte
75 jsr copyjv ; Copy one byte
76 cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
79 ; Copy the callback vectors into the driver space
82 ldy #(MOUSE_HDR::CALLBACKS + .sizeof(MOUSE_HDR::CALLBACKS) - 1)
84 ldy #.sizeof(MOUSE_CALLBACKS)-1
90 dec tmp2 ; Skip opcode byte
94 ; Call driver install routine
98 ; Install the IRQ vector if the driver needs it. A/X contains the error code
99 ; from mouse_install, so don't use it.
101 ldy mouse_irq+2 ; Check high byte of IRQ vector
102 beq @L3 ; Jump if vector invalid
103 ldy #$4C ; Jump opcode
104 sty mouse_irq ; Activate IRQ routine
107 ; Driver signature invalid. One word is still on the stack
110 lda #MOUSE_ERR_INV_DRIVER
114 ; Copy one byte from the jump vectors
122 ; Copy one byte from the callback vectors
131 ;----------------------------------------------------------------------------
132 ; unsigned char __fastcall__ mouse_uninstall (void);
133 ; /* Uninstall the currently loaded driver. Returns an error code. */
136 lda #$60 ; RTS opcode
137 sta mouse_irq ; Disable IRQ entry point
139 jsr mouse_uninstall ; Call driver routine
141 mouse_clear_ptr: ; External entry point
144 sta _mouse_drv+1 ; Clear the driver pointer