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