]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/cbm510-stdjoy.s
remove superfluous ".code" line
[cc65] / libsrc / cbm510 / cbm510-stdjoy.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         .include        "extzp.inc"
15
16         .macpack        generic
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22 .segment        "JUMPTABLE"
23
24 ; Driver signature
25
26         .byte   $6A, $6F, $79           ; "joy"
27         .byte   JOY_API_VERSION         ; Driver API version number
28
29 ; Button state masks (8 values)
30
31         .byte   $01                     ; JOY_UP
32         .byte   $02                     ; JOY_DOWN
33         .byte   $04                     ; JOY_LEFT
34         .byte   $08                     ; JOY_RIGHT
35         .byte   $10                     ; JOY_FIRE
36         .byte   $00                     ; JOY_FIRE2 unavailable
37         .byte   $00                     ; Future expansion
38         .byte   $00                     ; Future expansion
39
40 ; Jump table.
41
42         .addr   INSTALL
43         .addr   UNINSTALL
44         .addr   COUNT
45         .addr   READ
46         .addr   0                       ; IRQ entry unused
47
48 ; ------------------------------------------------------------------------
49 ; Constants
50
51 JOY_COUNT       = 2             ; Number of joysticks we support
52
53
54 ; ------------------------------------------------------------------------
55 ; Data.
56
57
58 .code
59
60 ; ------------------------------------------------------------------------
61 ; INSTALL routine. Is called after the driver is loaded into memory. If
62 ; possible, check if the hardware is present and determine the amount of
63 ; memory available.
64 ; Must return an JOY_ERR_xx code in a/x.
65 ;
66
67 INSTALL:
68         lda     #<JOY_ERR_OK
69         ldx     #>JOY_ERR_OK
70 ;       rts                     ; Run into UNINSTALL instead
71
72 ; ------------------------------------------------------------------------
73 ; UNINSTALL routine. Is called before the driver is removed from memory.
74 ; Can do cleanup or whatever. Must not return anything.
75 ;
76
77 UNINSTALL:
78         rts
79
80
81 ; ------------------------------------------------------------------------
82 ; COUNT: Return the total number of available joysticks in a/x.
83 ;
84
85 COUNT:
86         lda     #<JOY_COUNT
87         ldx     #>JOY_COUNT
88         rts
89
90 ; ------------------------------------------------------------------------
91 ; READ: Read a particular joystick passed in A.
92 ;
93
94 READ:   ldx     #$0F            ; Switch to the system bank
95         stx     IndReg
96         tax                     ; Save joystick number
97
98 ; Get the direction bits
99
100         ldy     #CIA::PRB
101         lda     (cia2),y        ; Read joystick inputs
102         sta     tmp1
103
104 ; Get the fire bits
105
106         ldy     #CIA::PRA
107         lda     (cia2),y
108
109 ; Make the result value
110
111         cpx     #$00            ; Joystick 0?
112         bne     @L1             ; Jump if no
113
114 ; Joystick 1, fire is in bit 6, direction in bit 0-3
115
116         asl     a
117         jmp     @L2
118
119 ; Joystick 2, fire is in bit 7, direction in bit 5-7
120
121 @L1:    ldx     #$00            ; High byte of return value
122         lsr     tmp1
123         lsr     tmp1
124         lsr     tmp1
125         lsr     tmp1
126
127 ; Mask the relavant bits, get the fire bit
128
129 @L2:    asl     a               ; Fire bit into carry
130         lda     tmp1
131         and     #$0F
132         bcc     @L3
133         ora     #$10
134 @L3:    eor     #$1F            ; All bits are inverted
135
136 ; Switch back to the execution bank and return the joystick mask in a/x
137
138         ldy     ExecReg
139         sty     IndReg
140         rts
141