]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/joy/cbm510-std.s
Removed IRQ support from joystick drivers.
[cc65] / libsrc / cbm510 / joy / cbm510-std.s
1 ;
2 ; Standard joystick driver for the Commodore 510 (aka P500). May be used
3 ; multiple times when linked to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2003-02-16
6 ;
7
8         .include        "zeropage.inc"
9         .include        "../extzp.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "cbm510.inc"
14
15         .macpack        generic
16         .macpack        module
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22         module_header   _cbm510_std_joy
23
24 ; Driver signature
25
26         .byte   $6A, $6F, $79           ; "joy"
27         .byte   JOY_API_VERSION         ; Driver API version number
28
29 ; Library reference
30
31         .addr   $0000
32
33 ; Jump table.
34
35         .addr   INSTALL
36         .addr   UNINSTALL
37         .addr   COUNT
38         .addr   READ
39
40 ; ------------------------------------------------------------------------
41 ; Constants
42
43 JOY_COUNT       = 2             ; Number of joysticks we support
44
45
46 ; ------------------------------------------------------------------------
47 ; Data.
48
49
50 .code
51
52 ; ------------------------------------------------------------------------
53 ; INSTALL routine. Is called after the driver is loaded into memory. If
54 ; possible, check if the hardware is present and determine the amount of
55 ; memory available.
56 ; Must return an JOY_ERR_xx code in a/x.
57 ;
58
59 INSTALL:
60         lda     #<JOY_ERR_OK
61         ldx     #>JOY_ERR_OK
62 ;       rts                     ; Run into UNINSTALL instead
63
64 ; ------------------------------------------------------------------------
65 ; UNINSTALL routine. Is called before the driver is removed from memory.
66 ; Can do cleanup or whatever. Must not return anything.
67 ;
68
69 UNINSTALL:
70         rts
71
72
73 ; ------------------------------------------------------------------------
74 ; COUNT: Return the total number of available joysticks in a/x.
75 ;
76
77 COUNT:
78         lda     #<JOY_COUNT
79         ldx     #>JOY_COUNT
80         rts
81
82 ; ------------------------------------------------------------------------
83 ; READ: Read a particular joystick passed in A.
84 ;
85
86 READ:   ldx     #$0F            ; Switch to the system bank
87         stx     IndReg
88         tax                     ; Save joystick number
89
90 ; Get the direction bits
91
92         ldy     #CIA::PRB
93         lda     (cia2),y        ; Read joystick inputs
94         sta     tmp1
95
96 ; Get the push button bits
97
98         ldy     #CIA::PRA
99         lda     (cia2),y
100
101 ; Make the result value
102
103         cpx     #$00            ; Joystick 0?
104         bne     @L1             ; Jump if no
105
106 ; Joystick 1, push button is in bit 6, direction in bit 0-3
107
108         asl     a
109         jmp     @L2
110
111 ; Joystick 2, push button is in bit 7, direction in bit 5-7
112
113 @L1:    ldx     #$00            ; High byte of return value
114         lsr     tmp1
115         lsr     tmp1
116         lsr     tmp1
117         lsr     tmp1
118
119 ; Mask the relavant bits, get the push button bit
120
121 @L2:    asl     a               ; push button bit into carry
122         lda     tmp1
123         and     #$0F
124         bcc     @L3
125         ora     #$10
126 @L3:    eor     #$1F            ; All bits are inverted
127
128 ; Switch back to the execution bank and return the joystick mask in a/x
129
130         ldy     ExecReg
131         sty     IndReg
132         rts
133