]> git.sur5r.net Git - cc65/blob - libsrc/c128/joy/c128-ptvjoy.s
Removed joy_masks array.
[cc65] / libsrc / c128 / joy / c128-ptvjoy.s
1 ;
2 ; PTV-4 Player joystick driver for the C128
3 ;
4 ; Ullrich von Bassewitz, 2003-09-28, using the C64 driver from
5 ; Groepaz/Hitmen, 2002-12-23, which is
6 ; obviously based on Ullrichs driver :)
7 ;
8
9         .include "zeropage.inc"
10
11         .include "joy-kernel.inc"
12         .include "joy-error.inc"
13         .include "c128.inc"
14
15         .macpack generic
16         .macpack module
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22         module_header   _c128_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 JOY_COUNT       = 4             ; Number of joysticks we support
45
46
47 .code
48
49 ; ------------------------------------------------------------------------
50 ; INSTALL routine. Is called after the driver is loaded into memory. If
51 ; possible, check if the hardware is present and determine the amount of
52 ; memory available.
53 ; Must return an JOY_ERR_xx code in a/x.
54 ;
55
56 INSTALL:
57         lda     #<JOY_ERR_OK
58         ldx     #>JOY_ERR_OK
59 ;       rts                     ; Run into UNINSTALL instead
60
61 ; ------------------------------------------------------------------------
62 ; UNINSTALL routine. Is called before the driver is removed from memory.
63 ; Can do cleanup or whatever. Must not return anything.
64 ;
65
66 UNINSTALL:
67         rts
68
69
70 ; ------------------------------------------------------------------------
71 ; COUNT: Return the total number of available joysticks in a/x.
72 ;
73
74 COUNT:
75         lda     #<JOY_COUNT
76         ldx     #>JOY_COUNT
77         rts
78
79 ; ------------------------------------------------------------------------
80 ; READ: Read a particular joystick passed in A.
81 ;
82
83 READ:   tax                     ; Joystick number into X
84         bne     joy2
85
86 ; Read joystick 1
87
88 joy1:   lda     #$7F
89         sei
90         sta     CIA1_PRA
91         lda     CIA1_PRB
92         cli
93         and     #$1F
94         eor     #$1F
95         rts
96
97 ; Read joystick 2
98
99 joy2:   dex
100         bne     joy3
101
102         lda     #$E0
103         ldy     #$FF
104         sei
105         sta     CIA1_DDRA
106         lda     CIA1_PRA
107         sty     CIA1_DDRA
108         cli
109         and     #$1F
110         eor     #$1F
111         rts
112
113 ; Read joystick 3
114
115 joy3:
116         lda     #%10000000      ; cia 2 port B Data-Direction
117         sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
118
119         dex
120         bne     joy4
121
122         lda     #$80            ; cia 2 port B read/write
123         sta     CIA2_PRB        ; (output one at PB7)
124
125         lda     CIA2_PRB        ; cia 2 port B read/write
126         and     #$1f            ; get bit 4-0 (PB4-PB0)
127         eor     #$1f
128         rts
129
130 ; Read joystick 4
131
132 joy4:
133         lda     #$00            ; cia 2 port B read/write
134         sta     CIA2_PRB        ; (output zero at PB7)
135
136         lda     CIA2_PRB        ; cia 2 port B read/write
137         and     #$0f            ; get bit 3-0 (PB3-PB0)
138         sta     tmp1            ; joy 4 directions
139
140         lda     CIA2_PRB        ; cia 2 port B read/write
141         and     #%00100000      ; get bit 5 (PB5)
142         lsr
143         ora     tmp1
144         eor     #$1f
145
146         ldx #0
147         rts