]> git.sur5r.net Git - cc65/blob - libsrc/c64/c64-stdjoy.s
8bbd7bbf8e596d8bf611ad491973e7857f3598ce
[cc65] / libsrc / c64 / c64-stdjoy.s
1 ;
2 ; Standard joystick driver for the C64. May be used multiple times when linked
3 ; to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2002-12-20
6 ;
7
8         .include        "zeropage.inc"
9
10         .include        "joy-kernel.inc"
11         .include        "joy-error.inc"
12         .include        "c64.inc"
13
14         .macpack        generic
15
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       = 2             ; Number of joysticks we support
50
51
52 ; ------------------------------------------------------------------------
53 ; Data.
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
69 ;       rts                     ; Run into UNINSTALL instead
70
71 ; ------------------------------------------------------------------------
72 ; UNINSTALL routine. Is called before the driver is removed from memory.
73 ; Can do cleanup or whatever. Must not return anything.
74 ;
75
76 UNINSTALL:
77         rts
78
79
80 ; ------------------------------------------------------------------------
81 ; COUNT: Return the total number of available joysticks in a/x.
82 ;
83
84 COUNT:
85         lda     #<JOY_COUNT
86         ldx     #>JOY_COUNT
87         rts
88
89 ; ------------------------------------------------------------------------
90 ; READ: Read a particular joystick passed in A.
91 ;
92
93 READ:   tax                     ; Joystick number into X
94         bne     joy2
95
96 ; Read joystick 1
97
98 joy1:   lda     #$7F
99         sei
100         sta     CIA1_PRA
101         lda     CIA1_PRB
102         cli
103         and     #$1F
104         eor     #$1F
105         rts
106
107 ; Read joystick 2
108
109 joy2:   ldx     #0
110         lda     #$E0
111         ldy     #$FF
112         sei
113         sta     CIA1_DDRA
114         lda     CIA1_PRA
115         sty     CIA1_DDRA
116         cli
117         and     #$1F
118         eor     #$1F
119         rts
120
121