]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/joy/atr5200std.s
add joystick driver -- trigger buttons are not queried yet
[cc65] / libsrc / atari5200 / joy / atr5200std.s
1 ;
2 ; Standard joystick driver for the Atari 5200.
3 ;
4 ; Christian Groessler, 2014-05-12
5 ;
6
7         .include        "zeropage.inc"
8
9         .include        "joy-kernel.inc"
10         .include        "joy-error.inc"
11         .include        "atari5200.inc"
12
13
14 ; ------------------------------------------------------------------------
15 ; Header. Includes jump table
16
17 .segment        "JUMPTABLE"
18
19 ; Driver signature
20
21         .byte   $6A, $6F, $79           ; "joy"
22         .byte   JOY_API_VERSION         ; Driver API version number
23
24 ; Library reference
25
26         .addr   $0000
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   $20                     ; JOY_FIRE2
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 .code
54
55 ; ------------------------------------------------------------------------
56 ; INSTALL routine. Is called after the driver is loaded into memory. If
57 ; possible, check if the hardware is present and determine the amount of
58 ; memory available.
59 ; Must return an JOY_ERR_xx code in a/x.
60 ;
61
62 INSTALL:
63         lda     #JOY_ERR_OK
64         ldx     #0
65 ;       rts                     ; Run into UNINSTALL instead
66
67 ; ------------------------------------------------------------------------
68 ; UNINSTALL routine. Is called before the driver is removed from memory.
69 ; Can do cleanup or whatever. Must not return anything.
70 ;
71
72 UNINSTALL:
73         rts
74
75
76 ; ------------------------------------------------------------------------
77 ; COUNT: Return the total number of available joysticks in a/x.
78 ;
79
80 COUNT:
81         lda     #JOY_COUNT
82         ldx     #0
83         rts
84
85 ; ------------------------------------------------------------------------
86 ; READ: Read a particular joystick passed in A.
87 ;
88
89 CENTER  =       228 / 2
90 SENSIVITY       = 16
91
92 READJOY:
93         and     #3              ; fix joystick number
94         asl     a
95         tax                     ; Joystick number * 2 (0-6) into X, index into ZP shadow registers
96         lda     #0              ; Initialize return value
97
98 ; Read joystick
99
100         ldy     PADDL0,x        ; get horizontal position
101         cpy     #CENTER-SENSIVITY
102         bcs     @chkleft
103
104         ora     #4              ; JOY_LEFT
105         bne     @updown
106
107 @chkleft:
108         cpy     #CENTER+SENSIVITY
109         bcc     @updown
110
111         ora     #8              ; JOY_RIGHT
112
113 @updown:ldy     PADDL0+1,x      ; get vertical position
114         cpy     #CENTER-SENSIVITY
115         bcs     @chkdown
116
117         ora     #1              ; JOY_UP
118         bne     @buttons
119
120 @chkdown:
121         cpy     #CENTER+SENSIVITY
122         bcc     @buttons
123
124         ora     #2              ; JOY_DOWN
125
126 @buttons:
127         ; @@@ TODO: BOTTON STATE
128
129         rts
130