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