]> git.sur5r.net Git - cc65/blob - libsrc/atari/atari-multijoy.s
Ignore only top level directories.
[cc65] / libsrc / atari / atari-multijoy.s
1 ;
2 ; MultiJoy 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 ; Stefan Haubenthal, 2009-04-10
7 ; Using code from Carsten Strotmann and help from Christian Groessler
8 ;
9
10         .include        "zeropage.inc"
11
12         .include        "joy-kernel.inc"
13         .include        "joy-error.inc"
14         .include        "atari.inc"
15
16         .macpack        generic
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22 .segment        "JUMPTABLE"
23
24 ; Driver signature
25
26         .byte   $6A, $6F, $79           ; "joy"
27         .byte   JOY_API_VERSION         ; Driver API version number
28
29 ; Button state masks (8 values)
30
31         .byte   $02                     ; JOY_UP
32         .byte   $04                     ; JOY_DOWN
33         .byte   $08                     ; JOY_LEFT
34         .byte   $10                     ; JOY_RIGHT
35         .byte   $01                     ; JOY_FIRE
36         .byte   $00                     ; JOY_FIRE2 not available
37         .byte   $00                     ; Future expansion
38         .byte   $00                     ; Future expansion
39
40 ; Jump table.
41
42         .addr   INSTALL
43         .addr   UNINSTALL
44         .addr   COUNT
45         .addr   READJOY
46         .addr   0                       ; IRQ entry not used
47
48 ; ------------------------------------------------------------------------
49 ; Constants
50
51 JOY_COUNT       = 8             ; Number of joysticks we support
52
53
54 ; ------------------------------------------------------------------------
55 ; Data.
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     #$30
69         sta     PACTL
70         lda     #$F0
71         sta     PORTA
72         lda     #$34
73         sta     PACTL
74         lda     #JOY_ERR_OK
75         ldx     #0
76 ;       rts                     ; Run into UNINSTALL instead
77
78 ; ------------------------------------------------------------------------
79 ; UNINSTALL routine. Is called before the driver is removed from memory.
80 ; Can do cleanup or whatever. Must not return anything.
81 ;
82
83 UNINSTALL:
84         rts
85
86
87 ; ------------------------------------------------------------------------
88 ; COUNT: Return the total number of available joysticks in a/x.
89 ;
90
91 COUNT:
92         lda     #JOY_COUNT
93         ldx     #0
94         rts
95
96 ; ------------------------------------------------------------------------
97 ; READ: Read a particular joystick passed in A.
98 ;
99
100 READJOY:
101         asl     a
102         asl     a
103         asl     a
104         asl     a
105         sta     PORTA
106
107 ; Read joystick
108
109         lda     PORTA           ; get position
110         and     #%00001111
111         asl     a
112         ora     TRIG0           ; add button information
113         eor     #%00011111
114         ldx     #0              ; fix X
115         rts