]> git.sur5r.net Git - cc65/blob - libsrc/atari/joy/atrstd.s
Create static drivers directly from source files.
[cc65] / libsrc / atari / joy / atrstd.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         .macpack        module
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22 .ifdef __ATARIXL__
23         module_header   _atrxstd_joy
24 .else
25         module_header   _atrstd_joy
26 .endif
27
28 ; Driver signature
29
30         .byte   $6A, $6F, $79           ; "joy"
31         .byte   JOY_API_VERSION         ; Driver API version number
32
33 ; Library reference
34
35         .addr   $0000
36
37 ; Button state masks (8 values)
38
39         .byte   $01                     ; JOY_UP
40         .byte   $02                     ; JOY_DOWN
41         .byte   $04                     ; JOY_LEFT
42         .byte   $08                     ; JOY_RIGHT
43         .byte   $10                     ; JOY_FIRE
44         .byte   $00                     ; JOY_FIRE2 not available
45         .byte   $00                     ; Future expansion
46         .byte   $00                     ; Future expansion
47
48 ; Jump table.
49
50         .addr   INSTALL
51         .addr   UNINSTALL
52         .addr   COUNT
53         .addr   READJOY
54         .addr   0                       ; IRQ entry not used
55
56 ; ------------------------------------------------------------------------
57 ; Constants
58
59 JOY_COUNT       = 4             ; Number of joysticks we support
60
61
62 ; ------------------------------------------------------------------------
63 ; Data.
64
65
66 .code
67
68 ; ------------------------------------------------------------------------
69 ; INSTALL routine. Is called after the driver is loaded into memory. If
70 ; possible, check if the hardware is present and determine the amount of
71 ; memory available.
72 ; Must return an JOY_ERR_xx code in a/x.
73 ;
74
75 INSTALL:
76         lda     #JOY_ERR_OK
77         ldx     #0
78 ;       rts                     ; Run into UNINSTALL instead
79
80 ; ------------------------------------------------------------------------
81 ; UNINSTALL routine. Is called before the driver is removed from memory.
82 ; Can do cleanup or whatever. Must not return anything.
83 ;
84
85 UNINSTALL:
86         rts
87
88
89 ; ------------------------------------------------------------------------
90 ; COUNT: Return the total number of available joysticks in a/x.
91 ;
92
93 COUNT:
94         lda     #JOY_COUNT
95         ldx     $fcd8
96         cpx     #$a2
97         beq     _400800
98         lsr     a               ; XL and newer machines only have 2 ports
99 _400800:
100         ldx     #0
101         rts
102
103 ; ------------------------------------------------------------------------
104 ; READ: Read a particular joystick passed in A.
105 ;
106
107 READJOY:
108         and     #3              ; fix joystick number
109         tax                     ; Joystick number (0-3) into X
110
111 ; Read joystick
112
113         lda     STRIG0,x        ; get button
114         asl     a
115         asl     a
116         asl     a
117         asl     a
118         ora     STICK0,x        ; add position information
119         eor     #$1F
120         ldx     #0              ; fix X
121         rts