]> git.sur5r.net Git - cc65/blob - libsrc/c64/c64-ptvjoy.s
Use symbolic names instead of numbers
[cc65] / libsrc / c64 / c64-ptvjoy.s
1 ;
2 ; PTV-4 Player joystick driver for the C64
3 ;
4 ; Groepaz/Hitmen, 2002-12-23
5 ; obviously based on Ullrichs driver :)
6 ;
7
8         .include "zeropage.inc"
9
10         .include "joy-kernel.inc"
11         .include "joy-error.inc"
12         .include "c64.inc"
13
14         .macpack generic
15
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
18
19         .segment "JUMPTABLE"
20
21 ; Driver signature
22
23         .byte   $6A, $6F, $79   ; "joy"
24         .byte   $00             ; Driver API version number
25
26 ; Button state masks (8 values)
27
28         .byte   $01                     ; JOY_UP
29         .byte   $02                     ; JOY_DOWN
30         .byte   $04                     ; JOY_LEFT
31         .byte   $08                     ; JOY_RIGHT
32         .byte   $10                     ; JOY_FIRE
33         .byte   $00                     ; Future expansion
34         .byte   $00                     ; Future expansion
35         .byte   $00                     ; Future expansion
36
37 ; Jump table.
38
39         .word   INSTALL
40         .word   DEINSTALL
41         .word   COUNT
42         .word   READ
43
44 ; ------------------------------------------------------------------------
45 ; Constants
46
47 JOY_COUNT       = 4             ; Number of joysticks we support
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
63 ;       rts                     ; Run into DEINSTALL instead
64
65 ; ------------------------------------------------------------------------
66 ; DEINSTALL routine. Is called before the driver is removed from memory.
67 ; Can do cleanup or whatever. Must not return anything.
68 ;
69
70 DEINSTALL:
71         rts
72
73
74 ; ------------------------------------------------------------------------
75 ; COUNT: Return the total number of available joysticks in a/x.
76 ;
77
78 COUNT:
79         lda     #<JOY_COUNT
80         ldx     #>JOY_COUNT
81         rts
82
83 ; ------------------------------------------------------------------------
84 ; READ: Read a particular joystick passed in A.
85 ;
86
87 READ:   tax                     ; Joystick number into X
88         bne     joy2
89
90 ; Read joystick 1
91
92 joy1:   lda     #$7F
93         sei
94         sta     CIA1_PRA
95         lda     CIA1_PRB
96         cli
97         and     #$1F
98         eor     #$1F
99         rts
100
101 ; Read joystick 2
102
103 joy2:   dex
104         bne     joy3
105
106         lda     #$E0
107         ldy     #$FF
108         sei
109         sta     CIA1_DDRA
110         lda     CIA1_PRA
111         sty     CIA1_DDRA
112         cli
113         and     #$1F
114         eor     #$1F
115         rts
116
117 ; Read joystick 3
118
119 joy3:   dex
120         bne     joy4
121
122         lda     #%10000000      ; cia 2 port B Data-Direction
123         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
124
125         lda     #$80            ; cia 2 port B read/write
126         sta     CIA2_PRB        ; (output one at PB7)
127
128         lda     CIA2_PRB        ; cia 2 port B read/write
129         and     #$1f            ; get bit 4-0 (PB4-PB0)
130         rts
131
132 ; Read joystick 4
133
134 joy4:   lda     #%10000000      ; cia 2 port B Data-Direction
135         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
136
137         lda     #$00            ; cia 2 port B read/write
138         sta     CIA2_PRB        ; (output zero at PB7)
139
140         lda     CIA2_PRB        ; cia 2 port B read/write
141         and     #$0f            ; get bit 3-0 (PB3-PB0)
142         sta     tmp1            ; joy 4 directions
143
144         lda     CIA2_PRB        ; cia 2 port B read/write
145         and     #%00100000      ; get bit 5 (PB5)
146         lsr
147         ora     tmp1
148
149         ldx #0
150         rts
151