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