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