]> git.sur5r.net Git - cc65/blob - libsrc/plus4/joy/plus4-stdjoy.s
Merge pull request #494 from jedeoric/master
[cc65] / libsrc / plus4 / joy / plus4-stdjoy.s
1 ;
2 ; Standard joystick driver for the Plus/4 and C16.
3 ; May be used multiple times when linked statically to an application.
4 ;
5 ; 2002-12-21, Ullrich von Bassewitz
6 ; 2016-06-18, Greg King
7 ;
8
9         .include        "joy-kernel.inc"
10         .include        "joy-error.inc"
11         .include        "plus4.inc"
12
13         .macpack        module
14
15
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
18
19         .if .xmatch ("MODULE_LABEL", .string(MODULE_LABEL))
20         module_header   _plus4_stdjoy_joy
21         .else
22         module_header   MODULE_LABEL
23         .endif
24
25 ; Driver signature
26
27         .byte   $6A, $6F, $79           ; ASCII "joy"
28         .byte   JOY_API_VERSION         ; Driver API version number
29
30 ; Library reference
31
32         .addr   $0000
33
34 ; Jump table.
35
36         .addr   INSTALL
37         .addr   UNINSTALL
38         .addr   COUNT
39         .addr   READ
40         .addr   0                       ; IRQ entry unused
41
42 ; ------------------------------------------------------------------------
43 ; Constants
44
45 JOY_COUNT       = 2             ; Number of joysticks we support
46
47
48 ; ------------------------------------------------------------------------
49 ; Data.
50
51
52 .code
53
54 ; ------------------------------------------------------------------------
55 ; INSTALL routine. Is called after the driver is loaded into memory. If
56 ; possible, check if the hardware is present and determine the amount of
57 ; memory available.
58 ; Must return an JOY_ERR_xx code in a/x.
59 ;
60
61 INSTALL:
62         lda     #<JOY_ERR_OK
63         ldx     #>JOY_ERR_OK
64 ;       rts                     ; Run into UNINSTALL instead
65
66 ; ------------------------------------------------------------------------
67 ; UNINSTALL routine. Is called before the driver is removed from memory.
68 ; Can do cleanup or whatever. Must not return anything.
69 ;
70
71 UNINSTALL:
72         rts
73
74
75 ; ------------------------------------------------------------------------
76 ; COUNT: Return the total number of available joysticks in a/x.
77 ;
78
79 COUNT:
80         lda     #<JOY_COUNT
81         ldx     #>JOY_COUNT
82         rts
83
84 ; ------------------------------------------------------------------------
85 ; READ: Read a particular joystick passed in A.
86 ;
87
88 READ:   ldy     #%11111011      ; Load index for joystick #1
89         tax                     ; Test joystick number
90         beq     @L1
91         ldy     #%11111101      ; Load index for joystick #2
92         ldx     #>$0000         ; (Return unsigned int)
93 @L1:    sei
94         sty     TED_KBD         ; Read a joystick ...
95         lda     TED_KBD         ; ... and some keys -- it's unavoidable
96         cli
97         eor     #%11111111
98
99 ; The push buttons are in bits 6 and 7.  Both of them cannot be %1 together.
100 ; Therefore, bit 6 can be merged with bit 7.
101
102         clc
103         adc     #%01000000
104         rts