]> git.sur5r.net Git - cc65/blob - libsrc/apple2/apple2-stdjoy.s
Improvements by Oliver Schmidt
[cc65] / libsrc / apple2 / apple2-stdjoy.s
1 ;
2 ; Standard joystick driver for the Apple ][. May be used multiple times when
3 ; linked to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2003-05-02
6 ; Using the readjoy code from Stefan Haubenthal
7 ;
8
9         .include        "zeropage.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "apple2.inc"
14
15         .macpack        generic
16
17
18 ; ------------------------------------------------------------------------
19 ; Constants
20
21 OFFS            = 10
22
23 ; ------------------------------------------------------------------------
24 ; ROM entry points
25
26 PREAD   :=      $FB1E   ; Read paddle in X, return AD conv. value in Y
27
28 ; ------------------------------------------------------------------------
29 ; Header. Includes jump table
30
31 .segment        "JUMPTABLE"
32
33 ; Driver signature
34
35         .byte   $6A, $6F, $79           ; "joy"
36         .byte   JOY_API_VERSION         ; Driver API version number
37
38 ; Button state masks (8 values)
39
40         .byte   $40
41         .byte   $80
42         .byte   $10
43         .byte   $20
44         .byte   $08
45         .byte   $00                     ; Future expansion
46         .byte   $00                     ; Future expansion
47         .byte   $00                     ; Future expansion
48
49 ; Jump table.
50
51         .word   INSTALL
52         .word   UNINSTALL
53         .word   COUNT
54         .word   READJOY
55
56 ; ------------------------------------------------------------------------
57 ; Constants
58
59 JOY_COUNT       = 2             ; Number of joysticks we support
60
61
62 ; ------------------------------------------------------------------------
63 ; Data.
64
65
66 .code
67
68 ; ------------------------------------------------------------------------
69 ; INSTALL routine. Is called after the driver is loaded into memory. If
70 ; possible, check if the hardware is present and determine the amount of
71 ; memory available.
72 ; Must return an JOY_ERR_xx code in a/x.
73 ;
74
75 INSTALL:
76         lda     #<JOY_ERR_OK
77         ldx     #>JOY_ERR_OK
78 ;       rts                     ; Run into UNINSTALL instead
79
80 ; ------------------------------------------------------------------------
81 ; UNINSTALL routine. Is called before the driver is removed from memory.
82 ; Can do cleanup or whatever. Must not return anything.
83 ;
84
85 UNINSTALL:
86         rts
87
88
89 ; ------------------------------------------------------------------------
90 ; COUNT: Return the total number of available joysticks in a/x.
91 ;
92
93 COUNT:
94         lda     #<JOY_COUNT
95         ldx     #>JOY_COUNT
96         rts
97
98 ; ------------------------------------------------------------------------
99 ; READ: Read a particular joystick passed in A.
100 ;
101
102 READJOY:
103         and     #$01            ; Fix joystick number
104         asl     a               ;
105         tax                     ; Joystick number (0,2) into X
106
107 ; Read joystick
108
109         lda     BUTN0,x         ; Check fire button
110         and     #$80            ; BTN 0 0 0 0 0 0 0
111
112         pha
113         jsr     PREAD           ; Read first paddle value
114         pla
115         cpy     #127-OFFS
116         ror     a               ; /LEFT BTN 0 0 0 0 0 0
117         cpy     #127+OFFS
118         ror     a               ; RIGHT /LEFT BTN 0 0 0 0 0
119
120         inx
121         pha
122         jsr     PREAD           ; Read second paddle
123         pla
124         cpy     #127-OFFS
125         ror     a               ; /UP RIGHT /LEFT BTN 0 0 0 0
126         cpy     #127+OFFS
127         ror     a               ; DOWN /UP RIGHT /LEFT BTN 0 0 0
128         eor     #%01010000      ; DOWN UP RIGHT LEFT BTN 0 0 0
129
130         ldx     #$00            ; fix X
131         rts
132
133