]> git.sur5r.net Git - cc65/blob - libsrc/atari/atari-stdjoy.s
The spans do now contain the size of a span, no longer the end offset.
[cc65] / libsrc / atari / atari-stdjoy.s
1 ;
2 ; Standard joystick driver for the Atari. May be used multiple times when linked
3 ; to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2002-12-21
6 ; Using the readjoy code from Christian Groessler
7 ;
8
9         .include        "zeropage.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "atari.inc"
14
15         .macpack        generic
16
17
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
20
21 .segment        "JUMPTABLE"
22
23 ; Driver signature
24
25         .byte   $6A, $6F, $79           ; "joy"
26         .byte   JOY_API_VERSION         ; Driver API version number
27
28 ; Button state masks (8 values)
29
30         .byte   $01                     ; JOY_UP
31         .byte   $02                     ; JOY_DOWN
32         .byte   $04                     ; JOY_LEFT
33         .byte   $08                     ; JOY_RIGHT
34         .byte   $10                     ; JOY_FIRE
35         .byte   $00                     ; JOY_FIRE2 not available
36         .byte   $00                     ; Future expansion
37         .byte   $00                     ; Future expansion
38
39 ; Jump table.
40
41         .addr   INSTALL
42         .addr   UNINSTALL
43         .addr   COUNT
44         .addr   READJOY
45         .addr   0                       ; IRQ entry not used
46
47 ; ------------------------------------------------------------------------
48 ; Constants
49
50 JOY_COUNT       = 4             ; Number of joysticks we support
51
52
53 ; ------------------------------------------------------------------------
54 ; Data.
55
56
57 .code
58
59 ; ------------------------------------------------------------------------
60 ; INSTALL routine. Is called after the driver is loaded into memory. If
61 ; possible, check if the hardware is present and determine the amount of
62 ; memory available.
63 ; Must return an JOY_ERR_xx code in a/x.
64 ;
65
66 INSTALL:
67         lda     #JOY_ERR_OK
68         ldx     #0
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     $fcd8
87         cpx     #$a2
88         beq     _400800
89         lsr     a               ; XL and newer machines only have 2 ports
90 _400800:
91         ldx     #0
92         rts
93
94 ; ------------------------------------------------------------------------
95 ; READ: Read a particular joystick passed in A.
96 ;
97
98 READJOY:
99         and     #3              ; fix joystick number
100         tax                     ; Joystick number (0-3) into X
101
102 ; Read joystick
103
104         lda     STRIG0,x        ; get button
105         asl     a
106         asl     a
107         asl     a
108         asl     a
109         ora     STICK0,x        ; add position information
110         eor     #$1F
111         ldx     #0              ; fix X
112         rts