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