]> git.sur5r.net Git - cc65/blob - libsrc/c128/joy/c128-ptvjoy.s
Fixed gcc compiler warning (#867)
[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
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:
132         lda     #$00            ; cia 2 port B read/write
133         sta     CIA2_PRB        ; (output zero at PB7)
134
135         lda     CIA2_PRB        ; cia 2 port B read/write
136         and     #$0f            ; get bit 3-0 (PB3-PB0)
137         sta     tmp1            ; joy 4 directions
138
139         lda     CIA2_PRB        ; cia 2 port B read/write
140         and     #%00100000      ; get bit 5 (PB5)
141         lsr
142         ora     tmp1
143         eor     #$1f
144
145         ldx #0
146         rts