]> git.sur5r.net Git - cc65/blob - libsrc/c64/joy/c64-ptvjoy.s
31850488c44dbb98ed7effbc905155ae5abd3d36
[cc65] / libsrc / c64 / joy / 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         .macpack module
16
17
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
20
21         module_header   _c64_ptvjoy_joy
22
23 ; Driver signature
24
25         .byte   $6A, $6F, $79   ; "joy"
26         .byte   JOY_API_VERSION ; Driver API version number
27
28 ; Library reference
29
30         .addr   $0000
31
32 ; Button state masks (8 values)
33
34         .byte   $01                     ; JOY_UP
35         .byte   $02                     ; JOY_DOWN
36         .byte   $04                     ; JOY_LEFT
37         .byte   $08                     ; JOY_RIGHT
38         .byte   $10                     ; JOY_FIRE
39         .byte   $00                     ; JOY_FIRE2 unavailable
40         .byte   $00                     ; Future expansion
41         .byte   $00                     ; Future expansion
42
43 ; Jump table.
44
45         .addr   INSTALL
46         .addr   UNINSTALL
47         .addr   COUNT
48         .addr   READ
49         .addr   0                       ; IRQ entry unused
50
51 ; ------------------------------------------------------------------------
52 ; Constants
53
54 JOY_COUNT       = 4             ; Number of joysticks we support
55
56
57 .code
58
59 ; ------------------------------------------------------------------------
60 ; INSTALL routine. Is called after the driver is loaded into memory. If
61 ; possible, check if the hardware is present and determine the amount of
62 ; memory available.
63 ; Must return an JOY_ERR_xx code in a/x.
64 ;
65
66 INSTALL:
67         lda     #<JOY_ERR_OK
68         ldx     #>JOY_ERR_OK
69 ;       rts                     ; Run into UNINSTALL instead
70
71 ; ------------------------------------------------------------------------
72 ; UNINSTALL routine. Is called before the driver is removed from memory.
73 ; Can do cleanup or whatever. Must not return anything.
74 ;
75
76 UNINSTALL:
77         rts
78
79
80 ; ------------------------------------------------------------------------
81 ; COUNT: Return the total number of available joysticks in a/x.
82 ;
83
84 COUNT:
85         lda     #<JOY_COUNT
86         ldx     #>JOY_COUNT
87         rts
88
89 ; ------------------------------------------------------------------------
90 ; READ: Read a particular joystick passed in A.
91 ;
92
93 READ:   tax                     ; Joystick number into X
94         bne     joy2
95
96 ; Read joystick 1
97
98 joy1:   lda     #$7F
99         sei
100         sta     CIA1_PRA
101         lda     CIA1_PRB
102         cli
103         and     #$1F
104         eor     #$1F
105         rts
106
107 ; Read joystick 2
108
109 joy2:   dex
110         bne     joy3
111
112         lda     #$E0
113         ldy     #$FF
114         sei
115         sta     CIA1_DDRA
116         lda     CIA1_PRA
117         sty     CIA1_DDRA
118         cli
119         and     #$1F
120         eor     #$1F
121         rts
122
123 ; Read joystick 3
124
125 joy3:
126         lda     #%10000000      ; cia 2 port B Data-Direction
127         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
128
129         dex
130         bne     joy4
131
132         lda     #$80            ; cia 2 port B read/write
133         sta     CIA2_PRB        ; (output one at PB7)
134
135         lda     CIA2_PRB        ; cia 2 port B read/write
136         and     #$1f            ; get bit 4-0 (PB4-PB0)
137         eor     #$1f
138         rts
139
140 ; Read joystick 4
141
142 joy4:   lda     #$00            ; cia 2 port B read/write
143         sta     CIA2_PRB        ; (output zero at PB7)
144
145         lda     CIA2_PRB        ; cia 2 port B read/write
146         and     #$0f            ; get bit 3-0 (PB3-PB0)
147         sta     tmp1            ; joy 4 directions
148
149         lda     CIA2_PRB        ; cia 2 port B read/write
150         and     #%00100000      ; get bit 5 (PB5)
151         lsr
152         ora     tmp1
153         eor     #$1f
154
155         ldx #0
156         rts
157