]> git.sur5r.net Git - cc65/blob - libsrc/joystick/joy-kernel.s
Removed (pretty inconsistently used) tab chars from source code base.
[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         .importzp       ptr1
8         .interruptor    joy_irq         ; Export as IRQ handler
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 _joy_masks:     .res    .sizeof(JOY_HDR::MASKS)
22
23 ; Jump table for the driver functions.
24 .data
25 joy_vectors:
26 joy_install:    jmp     $0000
27 joy_uninstall:  jmp     $0000
28 joy_count:      jmp     $0000
29 joy_read:       jmp     $0000
30 joy_irq:        .byte   $60, $00, $00   ; RTS plus two dummy bytes
31
32 ; Driver header signature
33 .rodata
34 joy_sig:        .byte   $6A, $6F, $79, JOY_API_VERSION  ; "joy", version
35
36
37 .code
38 ;----------------------------------------------------------------------------
39 ; unsigned char __fastcall__ joy_install (void* driver);
40 ; /* Install the driver once it is loaded */
41
42
43 _joy_install:
44         sta     _joy_drv
45         sta     ptr1
46         stx     _joy_drv+1
47         stx     ptr1+1
48
49 ; Check the driver signature
50
51         ldy     #.sizeof(joy_sig)-1
52 @L0:    lda     (ptr1),y
53         cmp     joy_sig,y
54         bne     inv_drv
55         dey
56         bpl     @L0
57
58 ; Copy the mask array
59
60         ldy     #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1
61         ldx     #.sizeof(JOY_HDR::MASKS)-1
62 @L1:    lda     (ptr1),y
63         sta     _joy_masks,x
64         dey
65         dex
66         bpl     @L1
67
68 ; Copy the jump vectors
69
70         ldy     #JOY_HDR::JUMPTAB
71         ldx     #0
72 @L2:    inx                             ; Skip the JMP opcode
73         jsr     copy                    ; Copy one byte
74         jsr     copy                    ; Copy one byte
75         cpy     #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB))
76         bne     @L2
77
78         jsr     joy_install             ; Call driver install routine
79         tay                             ; Test error code
80         bne     @L3                     ; Bail out if install had errors
81
82 ; Install the IRQ vector if the driver needs it. A/X contains the error code
83 ; from joy_install, so don't use it.
84
85         ldy     joy_irq+2               ; Check high byte of IRQ vector
86         beq     @L3                     ; Jump if vector invalid
87         ldy     #$4C                    ; JMP opcode
88         sty     joy_irq                 ; Activate IRQ routine
89 @L3:    rts
90
91 ; Driver signature invalid
92
93 inv_drv:
94         lda     #JOY_ERR_INV_DRIVER
95         ldx     #0
96         rts
97
98 ; Copy one byte from the jump vectors
99
100 copy:   lda     (ptr1),y
101         iny
102 set:    sta     joy_vectors,x
103         inx
104         rts
105
106 ;----------------------------------------------------------------------------
107 ; unsigned char joy_uninstall (void);
108 ; /* Uninstall the currently loaded driver. Note: This call does not free
109 ;  * allocated memory.
110 ;  */
111
112 _joy_uninstall:
113         lda     #$60                    ; RTS opcode
114         sta     joy_irq                 ; Disable IRQ entry point
115
116         jsr     joy_uninstall           ; Call the driver routine
117
118 _joy_clear_ptr:                         ; External entry point
119         lda     #0
120         sta     _joy_drv
121         sta     _joy_drv+1              ; Clear the driver pointer
122
123         tax                             ; Return zero
124         rts