]> git.sur5r.net Git - cc65/blob - libsrc/c64/c64-ptvjoy.s
60950ff5920ebc47e675e04d16c98faef2bfcb17
[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   JOY_API_VERSION ; 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   UNINSTALL
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 ;       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:   tax                     ; Joystick number into X
87         bne     joy2
88
89 ; Read joystick 1
90
91 joy1:   lda     #$7F
92         sei
93         sta     CIA1_PRA
94         lda     CIA1_PRB
95         cli
96         and     #$1F
97         eor     #$1F
98         rts
99
100 ; Read joystick 2
101
102 joy2:   dex
103         bne     joy3
104
105         lda     #$E0
106         ldy     #$FF
107         sei
108         sta     CIA1_DDRA
109         lda     CIA1_PRA
110         sty     CIA1_DDRA
111         cli
112         and     #$1F
113         eor     #$1F
114         rts
115
116 ; Read joystick 3
117
118 joy3:   dex
119         bne     joy4
120
121         lda     #%10000000      ; cia 2 port B Data-Direction
122         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
123
124         lda     #$80            ; cia 2 port B read/write
125         sta     CIA2_PRB        ; (output one at PB7)
126
127         lda     CIA2_PRB        ; cia 2 port B read/write
128         and     #$1f            ; get bit 4-0 (PB4-PB0)
129         rts
130
131 ; Read joystick 4
132
133 joy4:   lda     #%10000000      ; cia 2 port B Data-Direction
134         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
135
136         lda     #$00            ; cia 2 port B read/write
137         sta     CIA2_PRB        ; (output zero at PB7)
138
139         lda     CIA2_PRB        ; cia 2 port B read/write
140         and     #$0f            ; get bit 3-0 (PB3-PB0)
141         sta     tmp1            ; joy 4 directions
142
143         lda     CIA2_PRB        ; cia 2 port B read/write
144         and     #%00100000      ; get bit 5 (PB5)
145         lsr
146         ora     tmp1
147
148         ldx #0
149         rts
150