]> git.sur5r.net Git - cc65/blob - libsrc/vic20/joy/vic20-ptvjoy.s
Removed joy_masks array.
[cc65] / libsrc / vic20 / joy / vic20-ptvjoy.s
1 ;
2 ; PTV-3 Player joystick driver for the VIC20
3 ;
4 ; Stefan Haubenthal, 2005-05-25
5 ; Groepaz/Hitmen, 2002-12-23
6 ; obviously based on Ullrichs driver :)
7 ; Using code from Steve Schmidtke
8 ;
9
10         .include "zeropage.inc"
11
12         .include "joy-kernel.inc"
13         .include "joy-error.inc"
14         .include "vic20.inc"
15
16         .macpack module
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22         module_header   _vic20_ptvjoy_joy
23
24 ; Driver signature
25
26         .byte   $6A, $6F, $79   ; "joy"
27         .byte   JOY_API_VERSION ; Driver API version number
28
29 ; Library reference
30
31         .addr   $0000
32
33 ; Jump table.
34
35         .addr   INSTALL
36         .addr   UNINSTALL
37         .addr   COUNT
38         .addr   READ
39         .addr   0                       ; IRQ entry unused
40
41 ; ------------------------------------------------------------------------
42 ; Constants
43
44 VIA1_PRB        := VIA1         ; User port register
45 JOY_COUNT       = 3             ; Number of joysticks we support
46
47
48 .code
49
50 ; ------------------------------------------------------------------------
51 ; INSTALL routine. Is called after the driver is loaded into memory. If
52 ; possible, check if the hardware is present and determine the amount of
53 ; memory available.
54 ; Must return an JOY_ERR_xx code in a/x.
55 ;
56
57 INSTALL:
58         lda     #<JOY_ERR_OK
59         ldx     #>JOY_ERR_OK
60 ;       rts                     ; Run into UNINSTALL instead
61
62 ; ------------------------------------------------------------------------
63 ; UNINSTALL routine. Is called before the driver is removed from memory.
64 ; Can do cleanup or whatever. Must not return anything.
65 ;
66
67 UNINSTALL:
68         rts
69
70
71 ; ------------------------------------------------------------------------
72 ; COUNT: Return the total number of available joysticks in a/x.
73 ;
74
75 COUNT:
76         lda     #<JOY_COUNT
77         ldx     #>JOY_COUNT
78         rts
79
80 ; ------------------------------------------------------------------------
81 ; READ: Read a particular joystick passed in A.
82 ;
83
84 READ:   tax                     ; Joystick number into X
85         bne     joy2
86
87 ; Read joystick 1
88
89 joy1:   lda     #$7F            ; mask for VIA2 JOYBIT: sw3
90         ldx     #$C3            ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4
91         sei                     ; necessary?
92
93         ldy     VIA2_DDRB       ; remember the date of DDRB
94         sta     VIA2_DDRB       ; set JOYBITS on this VIA for input
95         lda     VIA2_JOY        ; read JOYBIT: sw3
96         sty     VIA2_DDRB       ; restore the state of DDRB
97         asl                     ; Shift sw3 into carry
98
99         ldy     VIA1_DDRA       ; remember the state of DDRA
100         stx     VIA1_DDRA       ; set JOYBITS on this VIA for input
101         lda     VIA1_JOY        ; read JOYBITS: sw0,sw1,sw2,sw4
102         sty     VIA1_DDRA       ; restore the state of DDRA
103
104         cli                     ; necessary?
105         ror                     ; Shift sw3 into bit 7
106         and     #$9E            ; Mask relevant bits
107         eor     #$9E            ; Active states are inverted
108
109         rts
110
111 ; Read joystick 2
112
113 joy2:   lda     #%10000000      ; via port B Data-Direction
114         sta     VIA1_DDRB       ; bit 7: out    bit 6-0: in
115
116         dex
117         bne     joy3
118
119         lda     #$80            ; via port B read/write
120         sta     VIA1_PRB        ; (output one at PB7)
121
122         lda     VIA1_PRB        ; via port B read/write
123         and     #$1f            ; get bit 4-0 (PB4-PB0)
124         eor     #$1f
125         rts
126
127 ; Read joystick 3
128
129 joy3:   lda     #$00            ; via port B read/write
130         sta     VIA1_PRB        ; (output zero at PB7)
131
132         lda     VIA1_PRB        ; via port B read/write
133         and     #$0f            ; get bit 3-0 (PB3-PB0)
134         sta     tmp1            ; joy 4 directions
135
136         lda     VIA1_PRB        ; via port B read/write
137         and     #%00100000      ; get bit 5 (PB5)
138         lsr
139         ora     tmp1
140         eor     #$1f
141
142         ldx     #0
143         rts