]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/joy/cbm510-std.s
0c2efc12d3b2999395da8a813b8374e3daea11f6
[cc65] / libsrc / cbm510 / joy / cbm510-std.s
1 ;
2 ; Standard joystick driver for the Commodore 510 (aka P500). May be used
3 ; multiple times when linked to the statically application.
4 ;
5 ; Ullrich von Bassewitz, 2003-02-16
6 ;
7
8         .include        "zeropage.inc"
9         .include        "../extzp.inc"
10
11         .include        "joy-kernel.inc"
12         .include        "joy-error.inc"
13         .include        "cbm510.inc"
14
15         .macpack        generic
16         .macpack        module
17
18
19 ; ------------------------------------------------------------------------
20 ; Header. Includes jump table
21
22         module_header   _cbm510_std_joy
23
24 ; Driver signature
25
26         .byte   $6A, $6F, $79           ; "joy"
27         .byte   JOY_API_VERSION         ; Driver API version number
28
29 ; Library reference
30
31         .addr   $0000
32
33 ; Jump table.
34
35         .addr   INSTALL
36         .addr   UNINSTALL
37         .addr   COUNT
38         .addr   READ
39         .addr   0                       ; IRQ entry unused
40
41 ; ------------------------------------------------------------------------
42 ; Constants
43
44 JOY_COUNT       = 2             ; Number of joysticks we support
45
46
47 ; ------------------------------------------------------------------------
48 ; Data.
49
50
51 .code
52
53 ; ------------------------------------------------------------------------
54 ; INSTALL routine. Is called after the driver is loaded into memory. If
55 ; possible, check if the hardware is present and determine the amount of
56 ; memory available.
57 ; Must return an JOY_ERR_xx code in a/x.
58 ;
59
60 INSTALL:
61         lda     #<JOY_ERR_OK
62         ldx     #>JOY_ERR_OK
63 ;       rts                     ; Run into UNINSTALL instead
64
65 ; ------------------------------------------------------------------------
66 ; UNINSTALL routine. Is called before the driver is removed from memory.
67 ; Can do cleanup or whatever. Must not return anything.
68 ;
69
70 UNINSTALL:
71         rts
72
73
74 ; ------------------------------------------------------------------------
75 ; COUNT: Return the total number of available joysticks in a/x.
76 ;
77
78 COUNT:
79         lda     #<JOY_COUNT
80         ldx     #>JOY_COUNT
81         rts
82
83 ; ------------------------------------------------------------------------
84 ; READ: Read a particular joystick passed in A.
85 ;
86
87 READ:   ldx     #$0F            ; Switch to the system bank
88         stx     IndReg
89         tax                     ; Save joystick number
90
91 ; Get the direction bits
92
93         ldy     #CIA::PRB
94         lda     (cia2),y        ; Read joystick inputs
95         sta     tmp1
96
97 ; Get the push button bits
98
99         ldy     #CIA::PRA
100         lda     (cia2),y
101
102 ; Make the result value
103
104         cpx     #$00            ; Joystick 0?
105         bne     @L1             ; Jump if no
106
107 ; Joystick 1, push button is in bit 6, direction in bit 0-3
108
109         asl     a
110         jmp     @L2
111
112 ; Joystick 2, push button is in bit 7, direction in bit 5-7
113
114 @L1:    ldx     #$00            ; High byte of return value
115         lsr     tmp1
116         lsr     tmp1
117         lsr     tmp1
118         lsr     tmp1
119
120 ; Mask the relavant bits, get the push button bit
121
122 @L2:    asl     a               ; push button bit into carry
123         lda     tmp1
124         and     #$0F
125         bcc     @L3
126         ora     #$10
127 @L3:    eor     #$1F            ; All bits are inverted
128
129 ; Switch back to the execution bank and return the joystick mask in a/x
130
131         ldy     ExecReg
132         sty     IndReg
133         rts
134