]> git.sur5r.net Git - cc65/blob - libsrc/mouse/mouse-kernel.s
New loadable mouse drivers
[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
10         .include        "mouse-kernel.inc"
11
12
13
14 ;----------------------------------------------------------------------------
15 ; Variables
16
17
18 .bss
19 _mouse_drv:     .res    2               ; Pointer to driver
20
21 ; Jump table for the driver functions.
22 .data
23 mouse_vectors:
24 mouse_install:  jmp     return0
25 mouse_uninstall:jmp     return0
26 mouse_hide:     jmp     return0
27 mouse_show:     jmp     return0
28 mouse_box:      jmp     return0
29 mouse_move:     jmp     return0
30 mouse_buttons:  jmp     return0
31 mouse_pos:      jmp     return0
32 mouse_info:     jmp     return0
33
34 ; Driver header signature
35 .rodata
36 mouse_sig:      .byte   $6d, $6f, $75, MOUSE_API_VERSION    ; "mou", version
37
38
39 ;----------------------------------------------------------------------------
40 ; unsigned char __fastcall__ mouse_install (void* driver);
41 ; /* Install an already loaded driver. Returns an error code. */
42
43
44
45 _mouse_install:
46         sta     _mouse_drv
47         sta     ptr1
48         stx     _mouse_drv+1
49         stx     ptr1+1
50
51 ; Check the driver signature
52
53         ldy     #.sizeof(mouse_sig)-1
54 @L0:    lda     (ptr1),y
55         cmp     mouse_sig,y
56         bne     inv_drv
57         dey
58         bpl     @L0
59
60 ; Copy the jump vectors
61
62         ldy     #MOUSE_HDR::JUMPTAB
63         ldx     #0
64 @L1:    inx                             ; Skip the JMP opcode
65         jsr     copy                    ; Copy one byte
66         jsr     copy                    ; Copy one byte
67         cpy     #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB))
68         bne     @L1
69
70         jmp     mouse_install           ; Call driver install routine
71
72 ; Driver signature invalid
73
74 inv_drv:
75         lda     #MOUSE_ERR_INV_DRIVER
76         ldx     #0
77         rts
78
79 ; Copy one byte from the jump vectors
80
81 copy:   lda     (ptr1),y
82         sta     mouse_vectors,x
83         iny
84         inx
85         rts
86
87 ;----------------------------------------------------------------------------
88 ; unsigned char __fastcall__ mouse_uninstall (void);
89 ; /* Uninstall the currently loaded driver. Returns an error code. */
90
91 _mouse_uninstall:
92         jsr     mouse_uninstall         ; Call driver routine
93
94 mouse_clear_ptr:                        ; External entry point
95         lda     #0
96         sta     _mouse_drv
97         sta     _mouse_drv+1            ; Clear the driver pointer
98
99         tax
100         rts                             ; Return zero
101