]> git.sur5r.net Git - cc65/blob - libsrc/c64/joy/c64-stdjoy.s
Added library reference joy_libref to JOY interface.
[cc65] / libsrc / c64 / joy / 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 ; 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       = 2             ; Number of joysticks we support
54
55
56 ; ------------------------------------------------------------------------
57 ; Data.
58
59
60 .code
61
62 ; ------------------------------------------------------------------------
63 ; INSTALL routine. Is called after the driver is loaded into memory. If
64 ; possible, check if the hardware is present and determine the amount of
65 ; memory available.
66 ; Must return an JOY_ERR_xx code in a/x.
67 ;
68
69 INSTALL:
70         lda     #<JOY_ERR_OK
71         ldx     #>JOY_ERR_OK
72
73 ;       rts                     ; Run into UNINSTALL instead
74
75 ; ------------------------------------------------------------------------
76 ; UNINSTALL routine. Is called before the driver is removed from memory.
77 ; Can do cleanup or whatever. Must not return anything.
78 ;
79
80 UNINSTALL:
81         rts
82
83
84 ; ------------------------------------------------------------------------
85 ; COUNT: Return the total number of available joysticks in a/x.
86 ;
87
88 COUNT:
89         lda     #<JOY_COUNT
90         ldx     #>JOY_COUNT
91         rts
92
93 ; ------------------------------------------------------------------------
94 ; READ: Read a particular joystick passed in A.
95 ;
96
97 READ:   tax                     ; Joystick number into X
98         bne     joy2
99
100 ; Read joystick 1
101
102 joy1:   lda     #$7F
103         sei
104         sta     CIA1_PRA
105         lda     CIA1_PRB
106         cli
107         and     #$1F
108         eor     #$1F
109         rts
110
111 ; Read joystick 2
112
113 joy2:   ldx     #0
114         lda     #$E0
115         ldy     #$FF
116         sei
117         sta     CIA1_DDRA
118         lda     CIA1_PRA
119         sty     CIA1_DDRA
120         cli
121         and     #$1F
122         eor     #$1F
123         rts
124
125