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