]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/joy/atr5200std.s
Removed IRQ support from joystick drivers.
[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 ; Jump table.
31
32         .addr   INSTALL
33         .addr   UNINSTALL
34         .addr   COUNT
35         .addr   READJOY
36
37 .code
38
39 ; ------------------------------------------------------------------------
40 ; INSTALL routine. Is called after the driver is loaded into memory. If
41 ; possible, check if the hardware is present and determine the amount of
42 ; memory available.
43 ; Must return an JOY_ERR_xx code in a/x.
44 ;
45
46 INSTALL:
47         lda     #JOY_ERR_OK
48         ldx     #0
49 ;       rts                     ; Run into UNINSTALL instead
50
51 ; ------------------------------------------------------------------------
52 ; UNINSTALL routine. Is called before the driver is removed from memory.
53 ; Can do cleanup or whatever. Must not return anything.
54 ;
55
56 UNINSTALL:
57         rts
58
59
60 ; ------------------------------------------------------------------------
61 ; COUNT: Return the total number of available joysticks in a/x.
62 ;
63
64 COUNT:
65         lda     $FD32           ; check ROM version
66         cmp     #$E8
67         bne     @2port
68         lda     #4
69         .byte   $2C             ; bit opcode, eats the next 2 bytes
70 @2port: lda     #2
71         ldx     #0
72         rts
73
74 ; ------------------------------------------------------------------------
75 ; READ: Read a particular joystick passed in A.
76 ;
77
78 CENTER  =       228 / 2
79 SENSIVITY       = 16
80
81 READJOY:
82         and     #3              ; put joystick number in range, just in case
83         tay
84         asl     a
85         tax                     ; Joystick number * 2 (0-6) into X, index into ZP shadow registers
86
87         lda     #0              ; Initialize return value
88         cmp     TRIG0,y
89         bne     @notrg
90         lda     #$10            ; JOY_BTN
91
92 ; Read joystick
93
94 @notrg: ldy     PADDL0,x        ; get horizontal position
95         cpy     #CENTER-SENSIVITY
96         bcs     @chkleft
97
98         ora     #4              ; JOY_LEFT
99         bne     @updown
100
101 @chkleft:
102         cpy     #CENTER+SENSIVITY
103         bcc     @updown
104
105         ora     #8              ; JOY_RIGHT
106
107 @updown:ldy     PADDL0+1,x      ; get vertical position
108         cpy     #CENTER-SENSIVITY
109         bcs     @chkdown
110
111         ora     #1              ; JOY_UP
112         bne     @done
113
114 @chkdown:
115         cpy     #CENTER+SENSIVITY
116         bcc     @done
117
118         ora     #2              ; JOY_DOWN
119
120 @done:  rts