]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/joy/atr5200std.s
Fixed _textcolor definition.
[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     #$04            ; enable POT input from the joystick ports, see section "GTIA" in 
48         sta     CONSOL          ;   http://www.atarimuseum.com/videogames/consoles/5200/conv_to_5200.html
49         lda     #JOY_ERR_OK
50         ldx     #0
51 ;       rts                     ; Run into UNINSTALL instead
52
53 ; ------------------------------------------------------------------------
54 ; UNINSTALL routine. Is called before the driver is removed from memory.
55 ; Can do cleanup or whatever. Must not return anything.
56 ;
57
58 UNINSTALL:
59         rts
60
61
62 ; ------------------------------------------------------------------------
63 ; COUNT: Return the total number of available joysticks in a/x.
64 ;
65
66 COUNT:
67         lda     $FD32           ; check ROM version
68         cmp     #$E8
69         bne     @2port
70         lda     #4
71         .byte   $2C             ; bit opcode, eats the next 2 bytes
72 @2port: lda     #2
73         ldx     #0
74         rts
75
76 ; ------------------------------------------------------------------------
77 ; READ: Read a particular joystick passed in A.
78 ;
79
80 CENTER  =       228 / 2
81 SENSIVITY       = 16
82
83 READJOY:
84         and     #3              ; put joystick number in range, just in case
85         sta     jsnum           ; remember joystick number
86         tay
87         asl     a
88         tax                     ; Joystick number * 2 (0-6) into X, index into ZP shadow registers
89
90         lda     #0              ; Initialize return value
91         cmp     TRIG0,y
92         bne     @notrg
93         ora     #$10            ; JOY_BTN
94
95 ; Read joystick
96
97 @notrg: ldy     PADDL0,x        ; get horizontal position
98         cpy     #CENTER-SENSIVITY
99         bcs     @chkleft
100
101         ora     #4              ; JOY_LEFT
102         bne     @updown
103
104 @chkleft:
105         cpy     #CENTER+SENSIVITY
106         bcc     @updown
107
108         ora     #8              ; JOY_RIGHT
109
110 @updown:ldy     PADDL0+1,x      ; get vertical position
111         cpy     #CENTER-SENSIVITY
112         bcs     @chkdown
113
114         ora     #1              ; JOY_UP
115         bne     @done
116
117 @chkdown:
118         cpy     #CENTER+SENSIVITY
119         bcc     @done
120
121         ora     #2              ; JOY_DOWN
122
123 @done:  ldx     #0
124         ldy     jsnum
125         cmp     oldval,y
126         beq     @ret
127         sta     oldval,y
128         stx     ATRACT
129 @ret:   rts
130
131 .bss
132
133 oldval:.res     4
134 jsnum: .res     1