]> git.sur5r.net Git - cc65/blob - libsrc/c64/joy/c64-ptvjoy.s
Removed joy_masks array.
[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 ; Jump table.
33
34         .addr   INSTALL
35         .addr   UNINSTALL
36         .addr   COUNT
37         .addr   READ
38         .addr   0                       ; IRQ entry unused
39
40 ; ------------------------------------------------------------------------
41 ; Constants
42
43 JOY_COUNT       = 4             ; Number of joysticks we support
44
45
46 .code
47
48 ; ------------------------------------------------------------------------
49 ; INSTALL routine. Is called after the driver is loaded into memory. If
50 ; possible, check if the hardware is present and determine the amount of
51 ; memory available.
52 ; Must return an JOY_ERR_xx code in a/x.
53 ;
54
55 INSTALL:
56         lda     #<JOY_ERR_OK
57         ldx     #>JOY_ERR_OK
58 ;       rts                     ; Run into UNINSTALL instead
59
60 ; ------------------------------------------------------------------------
61 ; UNINSTALL routine. Is called before the driver is removed from memory.
62 ; Can do cleanup or whatever. Must not return anything.
63 ;
64
65 UNINSTALL:
66         rts
67
68
69 ; ------------------------------------------------------------------------
70 ; COUNT: Return the total number of available joysticks in a/x.
71 ;
72
73 COUNT:
74         lda     #<JOY_COUNT
75         ldx     #>JOY_COUNT
76         rts
77
78 ; ------------------------------------------------------------------------
79 ; READ: Read a particular joystick passed in A.
80 ;
81
82 READ:   tax                     ; Joystick number into X
83         bne     joy2
84
85 ; Read joystick 1
86
87 joy1:   lda     #$7F
88         sei
89         sta     CIA1_PRA
90         lda     CIA1_PRB
91         cli
92         and     #$1F
93         eor     #$1F
94         rts
95
96 ; Read joystick 2
97
98 joy2:   dex
99         bne     joy3
100
101         lda     #$E0
102         ldy     #$FF
103         sei
104         sta     CIA1_DDRA
105         lda     CIA1_PRA
106         sty     CIA1_DDRA
107         cli
108         and     #$1F
109         eor     #$1F
110         rts
111
112 ; Read joystick 3
113
114 joy3:
115         lda     #%10000000      ; cia 2 port B Data-Direction
116         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
117
118         dex
119         bne     joy4
120
121         lda     #$80            ; cia 2 port B read/write
122         sta     CIA2_PRB        ; (output one at PB7)
123
124         lda     CIA2_PRB        ; cia 2 port B read/write
125         and     #$1f            ; get bit 4-0 (PB4-PB0)
126         eor     #$1f
127         rts
128
129 ; Read joystick 4
130
131 joy4:   lda     #$00            ; cia 2 port B read/write
132         sta     CIA2_PRB        ; (output zero at PB7)
133
134         lda     CIA2_PRB        ; cia 2 port B read/write
135         and     #$0f            ; get bit 3-0 (PB3-PB0)
136         sta     tmp1            ; joy 4 directions
137
138         lda     CIA2_PRB        ; cia 2 port B read/write
139         and     #%00100000      ; get bit 5 (PB5)
140         lsr
141         ora     tmp1
142         eor     #$1f
143
144         ldx #0
145         rts
146