]> git.sur5r.net Git - cc65/blob - libsrc/apple2/apple2-stdjoy.s
Rename the standard joystick driver for the Apple ][.
[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 ; Header. Includes jump table
25
26 .segment        "JUMPTABLE"
27
28 ; Driver signature
29
30         .byte   $6A, $6F, $79           ; "joy"
31         .byte   $00                     ; Driver API version number
32
33 ; Button state masks (8 values)
34
35         .byte   $40
36         .byte   $80
37         .byte   $10
38         .byte   $20
39         .byte   $08
40         .byte   $00                     ; Future expansion
41         .byte   $00                     ; Future expansion
42         .byte   $00                     ; Future expansion
43
44 ; Jump table.
45
46         .word   INSTALL
47         .word   UNINSTALL
48         .word   COUNT
49         .word   READJOY
50
51 ; ------------------------------------------------------------------------
52 ; Constants
53
54 JOY_COUNT       = 2             ; Number of joysticks we support
55
56
57 ; ------------------------------------------------------------------------
58 ; Data.
59
60
61 .code
62
63 ; ------------------------------------------------------------------------
64 ; INSTALL routine. Is called after the driver is loaded into memory. If
65 ; possible, check if the hardware is present and determine the amount of
66 ; memory available.
67 ; Must return an JOY_ERR_xx code in a/x.
68 ;
69
70 INSTALL:
71         lda     #<JOY_ERR_OK
72         ldx     #>JOY_ERR_OK
73
74 ;       rts                     ; Run into DEINSTALL instead
75
76 ; ------------------------------------------------------------------------
77 ; UNINSTALL routine. Is called before the driver is removed from memory.
78 ; Can do cleanup or whatever. Must not return anything.
79 ;
80
81 UNINSTALL:
82         rts
83
84
85 ; ------------------------------------------------------------------------
86 ; COUNT: Return the total number of available joysticks in a/x.
87 ;
88
89 COUNT:
90         lda     #<JOY_COUNT
91         ldx     #>JOY_COUNT
92         rts
93
94 ; ------------------------------------------------------------------------
95 ; READ: Read a particular joystick passed in A.
96 ;
97
98 READJOY:
99         and     #$01            ; Fix joystick number
100         asl     a               ;
101         tax                     ; Joystick number (0,2) into X
102
103 ; Read joystick
104
105         lda     OPEN_APPLE,x    ; Check fire button
106         and     #$80            ; BTN 0 0 0 0 0 0 0
107
108         pha
109         jsr     PREAD           ; Read first paddle value
110         pla
111         cpy     #127-OFFS
112         ror     a               ; /LEFT BTN 0 0 0 0 0 0
113         cpy     #127+OFFS
114         ror     a               ; RIGHT /LEFT BTN 0 0 0 0 0
115
116         inx
117         pha
118         jsr     PREAD           ; Read second paddle
119         pla
120         cpy     #127-OFFS
121         ror     a               ; /UP RIGHT /LEFT BTN 0 0 0 0
122         cpy     #127+OFFS
123         ror     a               ; DOWN /UP RIGHT /LEFT BTN 0 0 0
124         eor     #%01010000      ; DOWN UP RIGHT LEFT BTN 0 0 0
125
126         ldx     #0              ; fix X
127         rts
128
129