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