]> git.sur5r.net Git - cc65/blob - libsrc/mouse/mouse-kernel.s
Two fixes from Stefan Haubenthal
[cc65] / libsrc / mouse / mouse-kernel.s
1 ;
2 ; Ullrich von Bassewitz, 2003-12-28
3 ;
4 ; Common functions of the mouse driver API.
5 ;
6
7         .import         return0
8         .importzp       ptr1
9         .condes         mouse_irq, 2            ; Export as IRQ handler
10
11         .include        "mouse-kernel.inc"
12
13
14
15 ;----------------------------------------------------------------------------
16 ; Variables
17
18
19 .bss
20 _mouse_drv:     .res    2               ; Pointer to driver
21
22 ; Jump table for the driver functions.
23 .data
24 mouse_vectors:
25 mouse_install:  jmp     return0
26 mouse_uninstall:jmp     return0
27 mouse_hide:     jmp     return0
28 mouse_show:     jmp     return0
29 mouse_box:      jmp     return0
30 mouse_move:     jmp     return0
31 mouse_buttons:  jmp     return0
32 mouse_pos:      jmp     return0
33 mouse_info:     jmp     return0
34 mouse_ioctl:    jmp     return0
35 mouse_irq:      .byte   $60, $00, $00   ; RTS plus two dummy bytes
36
37 ; Driver header signature
38 .rodata
39 mouse_sig:      .byte   $6d, $6f, $75, MOUSE_API_VERSION    ; "mou", version
40
41
42 ;----------------------------------------------------------------------------
43 ; unsigned char __fastcall__ mouse_install (void* driver);
44 ; /* Install an already loaded driver. Returns an error code. */
45
46
47
48 _mouse_install:
49         sta     _mouse_drv
50         sta     ptr1
51         stx     _mouse_drv+1
52         stx     ptr1+1
53
54 ; Check the driver signature
55
56         ldy     #.sizeof(mouse_sig)-1
57 @L0:    lda     (ptr1),y
58         cmp     mouse_sig,y
59         bne     inv_drv
60         dey
61         bpl     @L0
62
63 ; Copy the jump vectors
64
65         ldy     #MOUSE_HDR::JUMPTAB
66         ldx     #0
67 @L1:    inx                             ; Skip the JMP opcode
68         jsr     copy                    ; Copy one byte
69         jsr     copy                    ; Copy one byte
70         cpy     #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
71         bne     @L1
72
73         jmp     mouse_install           ; Call driver install routine
74
75         ldy     mouse_irq+2             ; Check high byte of IRQ vector
76         beq     @L2                     ; Jump if vector invalid
77         ldy     #$4C                    ; Jump opcode
78         sty     mouse_irq               ; Activate IRQ routine
79 @L2:    rts
80
81 ; Driver signature invalid
82
83 inv_drv:
84         lda     #MOUSE_ERR_INV_DRIVER
85         ldx     #0
86         rts
87
88 ; Copy one byte from the jump vectors
89
90 copy:   lda     (ptr1),y
91         sta     mouse_vectors,x
92         iny
93         inx
94         rts
95
96 ;----------------------------------------------------------------------------
97 ; unsigned char __fastcall__ mouse_uninstall (void);
98 ; /* Uninstall the currently loaded driver. Returns an error code. */
99
100 _mouse_uninstall:
101         jsr     mouse_uninstall         ; Call driver routine
102
103         lda     #$60                    ; RTS opcode
104         sta     mouse_irq               ; Disable IRQ entry point
105
106 mouse_clear_ptr:                        ; External entry point
107         lda     #0
108         sta     _mouse_drv
109         sta     _mouse_drv+1            ; Clear the driver pointer
110
111         tax
112         rts                             ; Return zero
113