]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/joy/atr5200std.s
Merge pull request #249 from polluks/master
[cc65] / libsrc / atari5200 / joy / atr5200std.s
1 ;
2 ; Standard joystick driver for the Atari 5200.
3 ;
4 ; Christian Groessler, 2014-05-28
5 ;
6
7         .include        "zeropage.inc"
8
9         .include        "joy-kernel.inc"
10         .include        "joy-error.inc"
11         .include        "atari5200.inc"
12
13         .macpack        module
14
15
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
18
19         module_header   _atr5200std_joy
20
21 ; Driver signature
22
23         .byte   $6A, $6F, $79           ; "joy"
24         .byte   JOY_API_VERSION         ; Driver API version number
25
26 ; Library reference
27
28         .addr   $0000
29
30 ; Button state masks (8 values)
31
32         .byte   $01             ; JOY_UP
33         .byte   $02             ; JOY_DOWN
34         .byte   $04             ; JOY_LEFT
35         .byte   $08             ; JOY_RIGHT
36         .byte   $10             ; JOY_FIRE
37         .byte   $20             ; JOY_FIRE2
38         .byte   $00             ; Future expansion
39         .byte   $00             ; Future expansion
40
41 ; Jump table.
42
43         .addr   INSTALL
44         .addr   UNINSTALL
45         .addr   COUNT
46         .addr   READJOY
47         .addr   0               ; IRQ entry not used
48
49 .code
50
51 ; ------------------------------------------------------------------------
52 ; INSTALL routine. Is called after the driver is loaded into memory. If
53 ; possible, check if the hardware is present and determine the amount of
54 ; memory available.
55 ; Must return an JOY_ERR_xx code in a/x.
56 ;
57
58 INSTALL:
59         lda     #JOY_ERR_OK
60         ldx     #0
61 ;       rts                     ; Run into UNINSTALL instead
62
63 ; ------------------------------------------------------------------------
64 ; UNINSTALL routine. Is called before the driver is removed from memory.
65 ; Can do cleanup or whatever. Must not return anything.
66 ;
67
68 UNINSTALL:
69         rts
70
71
72 ; ------------------------------------------------------------------------
73 ; COUNT: Return the total number of available joysticks in a/x.
74 ;
75
76 COUNT:
77         lda     $FD32           ; check ROM version
78         cmp     #$E8
79         bne     @2port
80         lda     #4
81         .byte   $2C             ; bit opcode, eats the next 2 bytes
82 @2port: lda     #2
83         ldx     #0
84         rts
85
86 ; ------------------------------------------------------------------------
87 ; READ: Read a particular joystick passed in A.
88 ;
89
90 CENTER  =       228 / 2
91 SENSIVITY       = 16
92
93 READJOY:
94         and     #3              ; put joystick number in range, just in case
95         tay
96         asl     a
97         tax                     ; Joystick number * 2 (0-6) into X, index into ZP shadow registers
98
99         lda     #0              ; Initialize return value
100         cmp     TRIG0,y
101         bne     @notrg
102         lda     #$10            ; JOY_FIRE
103
104 ; Read joystick
105
106 @notrg: ldy     PADDL0,x        ; get horizontal position
107         cpy     #CENTER-SENSIVITY
108         bcs     @chkleft
109
110         ora     #4              ; JOY_LEFT
111         bne     @updown
112
113 @chkleft:
114         cpy     #CENTER+SENSIVITY
115         bcc     @updown
116
117         ora     #8              ; JOY_RIGHT
118
119 @updown:ldy     PADDL0+1,x      ; get vertical position
120         cpy     #CENTER-SENSIVITY
121         bcs     @chkdown
122
123         ora     #1              ; JOY_UP
124         bne     @done
125
126 @chkdown:
127         cpy     #CENTER+SENSIVITY
128         bcc     @done
129
130         ora     #2              ; JOY_DOWN
131
132 @done:  rts