]> git.sur5r.net Git - cc65/blob - libsrc/c64/c64-ptvjoy.s
Ignore only top level directories.
[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                     ; JOY_FIRE2 unavailable
34         .byte   $00                     ; Future expansion
35         .byte   $00                     ; Future expansion
36
37 ; Jump table.
38
39         .addr   INSTALL
40         .addr   UNINSTALL
41         .addr   COUNT
42         .addr   READ
43         .addr   0                       ; IRQ entry unused
44
45 ; ------------------------------------------------------------------------
46 ; Constants
47
48 JOY_COUNT       = 4             ; Number of joysticks we support
49
50
51 .code
52
53 ; ------------------------------------------------------------------------
54 ; INSTALL routine. Is called after the driver is loaded into memory. If
55 ; possible, check if the hardware is present and determine the amount of
56 ; memory available.
57 ; Must return an JOY_ERR_xx code in a/x.
58 ;
59
60 INSTALL:
61         lda     #<JOY_ERR_OK
62         ldx     #>JOY_ERR_OK
63 ;       rts                     ; Run into UNINSTALL instead
64
65 ; ------------------------------------------------------------------------
66 ; UNINSTALL routine. Is called before the driver is removed from memory.
67 ; Can do cleanup or whatever. Must not return anything.
68 ;
69
70 UNINSTALL:
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:
120         lda     #%10000000      ; cia 2 port B Data-Direction
121         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
122
123         dex
124         bne     joy4
125
126         lda     #$80            ; cia 2 port B read/write
127         sta     CIA2_PRB        ; (output one at PB7)
128
129         lda     CIA2_PRB        ; cia 2 port B read/write
130         and     #$1f            ; get bit 4-0 (PB4-PB0)
131         eor     #$1f
132         rts
133
134 ; Read joystick 4
135
136 joy4:   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         eor     #$1f
148
149         ldx #0
150         rts
151