]> git.sur5r.net Git - cc65/blob - libsrc/joystick/joy-kernel.s
Make joy_install, joy_uninstall user callable functions
[cc65] / libsrc / joystick / joy-kernel.s
1 ;
2 ; Ullrich von Bassewitz, 2002-12-20
3 ;
4 ; Common functions of the joystick API.
5 ;
6
7         .export         _joy_install, _joy_uninstall, _joy_masks
8         .export         joy_clear_ptr
9               
10         .importzp       ptr1
11
12         .include        "joy-kernel.inc"
13         .include        "joy-error.inc"
14
15
16 ;----------------------------------------------------------------------------
17 ; Variables
18
19
20 .bss
21 _joy_drv:       .res    2               ; Pointer to driver
22
23 _joy_masks:     .res    JOY_MASK_COUNT
24
25 ; Jump table for the driver functions.
26 .data
27 joy_vectors:
28 joy_install:    jmp     $0000
29 joy_uninstall:  jmp     $0000
30 joy_count:      jmp     $0000
31 joy_read:       jmp     $0000
32
33 ; Driver header signature
34 .rodata
35 joy_sig:        .byte   $6A, $6F, $79, $00      ; "joy", version
36 joy_sig_len     = * - joy_sig
37
38
39 ;----------------------------------------------------------------------------
40 ; unsigned char __fastcall__ joy_install (void* driver);
41 ; /* Install the driver once it is loaded */
42
43
44 _joy_install:
45         sta     _joy_drv
46         sta     ptr1
47         stx     _joy_drv+1
48         stx     ptr1+1
49
50 ; Check the driver signature
51
52         ldy     #joy_sig_len-1
53 @L0:    lda     (ptr1),y
54         cmp     joy_sig,y
55         bne     inv_drv
56         dey
57         bpl     @L0
58
59 ; Copy the mask array
60
61         ldy     #JOY_MASKS + JOY_MASK_COUNT - 1
62         ldx     #JOY_MASK_COUNT-1
63 @L1:    lda     (ptr1),y
64         sta     _joy_masks,x
65         dey
66         dex
67         bpl     @L1
68
69 ; Copy the jump vectors
70
71         ldy     #JOY_HDR_JUMPTAB
72         ldx     #0
73 @L2:    inx                             ; Skip the JMP opcode
74         jsr     copy                    ; Copy one byte
75         jsr     copy                    ; Copy one byte
76         cpx     #(JOY_HDR_JUMPCOUNT*3)
77         bne     @L2
78
79         jmp     joy_install             ; Call driver install routine
80
81 ; Driver signature invalid
82
83 inv_drv:
84         lda     #JOY_ERR_INV_DRIVER
85         ldx     #0
86         rts
87
88 ; Copy one byte from the jump vectors
89
90 copy:   lda     (ptr1),y
91         iny
92 set:    sta     joy_vectors,x
93         inx
94         rts
95
96 ;----------------------------------------------------------------------------
97 ; unsigned char __fastcall__ joy_uninstall (void);
98 ; /* Uninstall the currently loaded driver. Note: This call does not free
99 ;  * allocated memory.
100 ;  */
101
102 _joy_uninstall:
103         jsr     joy_uninstall           ; Call the driver routine
104
105 joy_clear_ptr:                          ; External entry point
106         lda     #0
107         sta     _joy_drv
108         sta     _joy_drv+1              ; Clear the driver pointer
109
110         tax                             ; Return zero
111         rts
112