]> git.sur5r.net Git - cc65/blob - libsrc/apple2/apple2-stdjoy.s
Reworked version 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 ; Header. Includes jump table
25
26 .segment        "JUMPTABLE"
27
28 ; Driver signature
29
30         .byte   $6A, $6F, $79           ; "joy"
31         .byte   JOY_API_VERSION         ; 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 ;       rts                     ; Run into UNINSTALL instead
74
75 ; ------------------------------------------------------------------------
76 ; UNINSTALL routine. Is called before the driver is removed from memory.
77 ; Can do cleanup or whatever. Must not return anything.
78 ;
79
80 UNINSTALL:
81         rts
82
83
84 ; ------------------------------------------------------------------------
85 ; COUNT: Return the total number of available joysticks in a/x.
86 ;
87
88 COUNT:
89         lda     #<JOY_COUNT
90         ldx     #>JOY_COUNT
91         rts
92
93 ; ------------------------------------------------------------------------
94 ; READ: Read a particular joystick passed in A.
95 ;
96
97 READJOY:
98         and     #$01            ; Fix joystick number
99         asl     a               ;
100         tax                     ; Joystick number (0,2) into X
101
102 ; Read joystick
103
104         lda     BUTN0,x         ; Check fire button
105         and     #$80            ; BTN 0 0 0 0 0 0 0
106
107         pha
108         jsr     PREAD           ; Read first paddle value
109         pla
110         cpy     #127-OFFS
111         ror     a               ; /LEFT BTN 0 0 0 0 0 0
112         cpy     #127+OFFS
113         ror     a               ; RIGHT /LEFT BTN 0 0 0 0 0
114
115         inx
116         pha
117         jsr     PREAD           ; Read second paddle
118         pla
119         cpy     #127-OFFS
120         ror     a               ; /UP RIGHT /LEFT BTN 0 0 0 0
121         cpy     #127+OFFS
122         ror     a               ; DOWN /UP RIGHT /LEFT BTN 0 0 0
123         eor     #%01010000      ; DOWN UP RIGHT LEFT BTN 0 0 0
124
125         ldx     #$00            ; fix X
126         rts
127
128