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