]> git.sur5r.net Git - cc65/blob - libsrc/plus4/joy/plus4-stdjoy.s
Merge remote-tracking branch 'upstream/master' into creativision
[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 ; Button state masks (8 values)
35
36         .byte   $01                     ; JOY_UP
37         .byte   $02                     ; JOY_DOWN
38         .byte   $04                     ; JOY_LEFT
39         .byte   $08                     ; JOY_RIGHT
40         .byte   $80                     ; JOY_FIRE
41         .byte   $00                     ; JOY_FIRE2 unavailable
42         .byte   $00                     ; Future expansion
43         .byte   $00                     ; Future expansion
44
45 ; Jump table.
46
47         .addr   INSTALL
48         .addr   UNINSTALL
49         .addr   COUNT
50         .addr   READ
51         .addr   0                       ; IRQ entry unused
52
53 ; ------------------------------------------------------------------------
54 ; Constants
55
56 JOY_COUNT       = 2             ; Number of joysticks we support
57
58
59 ; ------------------------------------------------------------------------
60 ; Data.
61
62
63 .code
64
65 ; ------------------------------------------------------------------------
66 ; INSTALL routine. Is called after the driver is loaded into memory. If
67 ; possible, check if the hardware is present and determine the amount of
68 ; memory available.
69 ; Must return an JOY_ERR_xx code in a/x.
70 ;
71
72 INSTALL:
73         lda     #<JOY_ERR_OK
74         ldx     #>JOY_ERR_OK
75 ;       rts                     ; Run into UNINSTALL instead
76
77 ; ------------------------------------------------------------------------
78 ; UNINSTALL routine. Is called before the driver is removed from memory.
79 ; Can do cleanup or whatever. Must not return anything.
80 ;
81
82 UNINSTALL:
83         rts
84
85
86 ; ------------------------------------------------------------------------
87 ; COUNT: Return the total number of available joysticks in a/x.
88 ;
89
90 COUNT:
91         lda     #<JOY_COUNT
92         ldx     #>JOY_COUNT
93         rts
94
95 ; ------------------------------------------------------------------------
96 ; READ: Read a particular joystick passed in A.
97 ;
98
99 READ:   ldy     #%11111011      ; Load index for joystick #1
100         tax                     ; Test joystick number
101         beq     @L1
102         ldy     #%11111101      ; Load index for joystick #2
103         ldx     #>$0000         ; (Return unsigned int)
104 @L1:    sei
105         sty     TED_KBD         ; Read a joystick ...
106         lda     TED_KBD         ; ... and some keys -- it's unavoidable
107         cli
108         eor     #%11111111
109
110 ; The fire buttons are in bits 6 and 7.  Both of them cannot be %1 together.
111 ; Therefore, bit 6 can be merged with bit 7.
112
113         clc
114         adc     #%01000000
115         rts